[patch 1/6] Add MMC password protection (lock/unlock) support V4
- From: Carlos Aguiar <carlos.aguiar@xxxxxxxxxxx>
- Date: Tue, 31 Jan 2006 16:16:37 -0400
When a card is locked, only commands from the "basic" and "lock card" classes
are accepted. To be able to use the other commands, the card must be unlocked
first.
This patch prevents the block driver from trying to run privileged class
commands on locked MMC cards, which will fail anyway.
Signed-off-by: Anderson Briglia <anderson.briglia@xxxxxxxxxxx>
Signed-off-by: Anderson Lizardo <anderson.lizardo@xxxxxxxxxxx>
Signed-off-by: Carlos Eduardo Aguiar <carlos.aguiar@xxxxxxxxxxx>
Signed-off-by: David Brownell <david-b@xxxxxxxxxxx>
Index: linux-omap-2.6.git/drivers/mmc/mmc_sysfs.c
===================================================================
--- linux-omap-2.6.git.orig/drivers/mmc/mmc_sysfs.c 2006-01-31 15:17:45.000000000 -0400
+++ linux-omap-2.6.git/drivers/mmc/mmc_sysfs.c 2006-01-31 15:22:07.000000000 -0400
@@ -16,6 +16,7 @@
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
+#include <linux/mmc/protocol.h>
#include "mmc.h"
@@ -69,13 +70,22 @@ static void mmc_release_card(struct devi
}
/*
- * This currently matches any MMC driver to any MMC card - drivers
- * themselves make the decision whether to drive this card in their
- * probe method. However, we force "bad" cards to fail.
+ * This currently matches any MMC driver to any MMC card - drivers themselves
+ * make the decision whether to drive this card in their probe method.
+ * However, we force "bad" cards to fail.
+ *
+ * We also fail for all locked cards; drivers expect to be able to do block
+ * I/O still on probe(), which is not possible while the card is locked.
+ * Device probing must be triggered sometime later to make the card available
+ * to the block driver.
*/
static int mmc_bus_match(struct device *dev, struct device_driver *drv)
{
struct mmc_card *card = dev_to_mmc_card(dev);
+ if (mmc_card_lockable(card) && mmc_card_locked(card)) {
+ dev_dbg(&card->dev, "card is locked; binding is deferred\n");
+ return 0;
+ }
return !mmc_card_bad(card);
}
Index: linux-omap-2.6.git/include/linux/mmc/card.h
===================================================================
--- linux-omap-2.6.git.orig/include/linux/mmc/card.h 2006-01-31 15:17:45.000000000 -0400
+++ linux-omap-2.6.git/include/linux/mmc/card.h 2006-01-31 15:22:07.000000000 -0400
@@ -61,6 +61,7 @@ struct mmc_card {
#define MMC_STATE_BAD (1<<2) /* unrecognised device */
#define MMC_STATE_SDCARD (1<<3) /* is an SD card */
#define MMC_STATE_READONLY (1<<4) /* card is read-only */
+#define MMC_STATE_LOCKED (1<<5) /* card is currently locked */
u32 raw_cid[4]; /* raw card CID */
u32 raw_csd[4]; /* raw card CSD */
u32 raw_scr[2]; /* raw card SCR */
@@ -74,12 +75,18 @@ struct mmc_card {
#define mmc_card_bad(c) ((c)->state & MMC_STATE_BAD)
#define mmc_card_sd(c) ((c)->state & MMC_STATE_SDCARD)
#define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
+#define mmc_card_locked(c) ((c)->state & MMC_STATE_LOCKED)
+#define mmc_card_clear_locked(c) ((c)->state &= ~MMC_STATE_LOCKED)
+
+#define mmc_card_lockable(c) (((c)->csd.cmdclass & CCC_LOCK_CARD) && \
+ ((c)->host->caps & MMC_CAP_LOCK_UNLOCK))
#define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
#define mmc_card_set_dead(c) ((c)->state |= MMC_STATE_DEAD)
#define mmc_card_set_bad(c) ((c)->state |= MMC_STATE_BAD)
#define mmc_card_set_sd(c) ((c)->state |= MMC_STATE_SDCARD)
#define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
+#define mmc_card_set_locked(c) ((c)->state |= MMC_STATE_LOCKED)
#define mmc_card_name(c) ((c)->cid.prod_name)
#define mmc_card_id(c) ((c)->dev.bus_id)
Index: linux-omap-2.6.git/include/linux/mmc/host.h
===================================================================
--- linux-omap-2.6.git.orig/include/linux/mmc/host.h 2006-01-31 15:17:45.000000000 -0400
+++ linux-omap-2.6.git/include/linux/mmc/host.h 2006-01-31 15:22:07.000000000 -0400
@@ -85,6 +85,8 @@ struct mmc_host {
unsigned long caps; /* Host capabilities */
#define MMC_CAP_4_BIT_DATA (1 << 0) /* Can the host do 4 bit transfers */
+#define MMC_CAP_LOCK_UNLOCK (1 << 1) /* Host password support capability */
+
/* host specific block data */
unsigned int max_seg_size; /* see blk_queue_max_segment_size */
Index: linux-omap-2.6.git/drivers/mmc/mmc.c
===================================================================
--- linux-omap-2.6.git.orig/drivers/mmc/mmc.c 2006-01-31 15:17:45.000000000 -0400
+++ linux-omap-2.6.git/drivers/mmc/mmc.c 2006-01-31 15:22:07.000000000 -0400
@@ -828,6 +828,11 @@ static void mmc_discover_cards(struct mm
list_add(&card->node, &host->cards);
}
+ if (cmd.resp[0] & R1_CARD_IS_LOCKED)
+ mmc_card_set_locked(card);
+ else
+ mmc_card_clear_locked(card);
+
card->state &= ~MMC_STATE_DEAD;
if (host->mode == MMC_MODE_SD) {
--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
- References:
- [patch 0/6] Add MMC password protection (lock/unlock) support V4
- From: Carlos Aguiar
- [patch 0/6] Add MMC password protection (lock/unlock) support V4
- Prev by Date: Re: [PATCH 10/11] LED: Add IDE disk activity LED trigger
- Next by Date: Re: vgacon scrolling problem [Was: Re: 2.6.16-rc1-mm4]
- Previous by thread: [patch 6/6] Add MMC password protection (lock/unlock) support V4
- Next by thread: [patch 3/6] Add MMC password protection (lock/unlock) support V4
- Index(es):
Relevant Pages
- Re: [RFC] MTD driver for MMC cards
... This is a new version of the driver I posted back in January. ... mtd layer
doesn't deal with media larger than 4GB anyway at ... * transfer a block to/from the card.
... * Initialize an mmc card. ... (Linux-Kernel) - [patch 1/5] [RFC] Add MMC password protection (lock/unlock) support
... This patch prevents the block driver from trying to run privileged class commands on
locked MMC cards, which will fail anyway. ... * themselves make the decision whether to
drive this card in their ... + * This currently matches any MMC driver to any MMC card
- drivers themselves ... (Linux-Kernel) - Linux 2.6 removable media block device driver question
... I'm trying to write a block driver for accessing an SD card through a memory-mapped
SPI module implemented in a Xilinx FPGA. ... I have finished the lower-level card access routines,
and can successfully read and write blocks, and even fdisk and mount the card. ... My next step
is to figure out how to handle card insertion and removal after the driver has been loaded, and how to
notify the kernel that there is now a disk present. ... Their sample block driver,
unfortunately, does not appear to show how to handle a disk that may change during execution, and may
not even be present some times. ... (Linux-Kernel) - [patch 1/5] Add MMC password protection (lock/unlock) support V3
... This patch prevents the block driver from trying to run privileged class commands on
locked MMC cards, which will fail anyway. ... * themselves make the decision whether to
drive this card in their ... + * This currently matches any MMC driver to any MMC card
- drivers themselves ... (Linux-Kernel) - RE: [UPDATED PATCH] EFI support for ia32 kernels
... >> reuse a single driver image for multiple architectures assuming there ...
As one of the people responsible for the EFI Specification and our ... Perhaps the UNDI
network card interface that Intel developed ... BIOS can't shadow that much ROM code.
... (Linux-Kernel)