alistair23-linux/drivers/mmc/core
Linus Walleij 97548575be mmc: block: Convert RPMB to a character device
The RPMB partition on the eMMC devices is a special area used
for storing cryptographically safe information signed by a
special secret key. To write and read records from this special
area, authentication is needed.

The RPMB area is *only* and *exclusively* accessed using
ioctl():s from userspace. It is not really a block device,
as blocks cannot be read or written from the device, also
the signed chunks that can be stored on the RPMB are actually
256 bytes, not 512 making a block device a real bad fit.

Currently the RPMB partition spawns a separate block device
named /dev/mmcblkNrpmb for each device with an RPMB partition,
including the creation of a block queue with its own kernel
thread and all overhead associated with this. On the Ux500
HREFv60 platform, for example, the two eMMCs means that two
block queues with separate threads are created for no use
whatsoever.

I have concluded that this block device design for RPMB is
actually pretty wrong. The RPMB area should have been designed
to be accessed from /dev/mmcblkN directly, using ioctl()s on
the main block device. It is however way too late to change
that, since userspace expects to open an RPMB device in
/dev/mmcblkNrpmb and we cannot break userspace.

This patch tries to amend the situation using the following
strategy:

- Stop creating a block device for the RPMB partition/area

- Instead create a custom, dynamic character device with
  the same name.

- Make this new character device support exactly the same
  set of ioctl()s as the old block device.

- Wrap the requests back to the same ioctl() handlers, but
  issue them on the block queue of the main partition/area,
  i.e. /dev/mmcblkN

We need to create a special "rpmb" bus type in order to get
udev and/or busybox hot/coldplug to instantiate the device
node properly.

Before the patch, this appears in 'ps aux':

101 root       0:00 [mmcqd/2rpmb]
123 root       0:00 [mmcqd/3rpmb]

After applying the patch these surplus block queue threads
are gone, but RPMB is as usable as ever using the userspace
MMC tools, such as 'mmc rpmb read-counter'.

We get instead those dynamice devices in /dev:

brw-rw----    1 root     root      179,   0 Jan  1  2000 mmcblk0
brw-rw----    1 root     root      179,   1 Jan  1  2000 mmcblk0p1
brw-rw----    1 root     root      179,   2 Jan  1  2000 mmcblk0p2
brw-rw----    1 root     root      179,   5 Jan  1  2000 mmcblk0p5
brw-rw----    1 root     root      179,   8 Jan  1  2000 mmcblk2
brw-rw----    1 root     root      179,  16 Jan  1  2000 mmcblk2boot0
brw-rw----    1 root     root      179,  24 Jan  1  2000 mmcblk2boot1
crw-rw----    1 root     root      248,   0 Jan  1  2000 mmcblk2rpmb
brw-rw----    1 root     root      179,  32 Jan  1  2000 mmcblk3
brw-rw----    1 root     root      179,  40 Jan  1  2000 mmcblk3boot0
brw-rw----    1 root     root      179,  48 Jan  1  2000 mmcblk3boot1
brw-rw----    1 root     root      179,  33 Jan  1  2000 mmcblk3p1
crw-rw----    1 root     root      248,   1 Jan  1  2000 mmcblk3rpmb

Notice the (248,0) and (248,1) character devices for RPMB.

Cc: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
2017-10-30 11:40:10 +01:00
..
block.c mmc: block: Convert RPMB to a character device 2017-10-30 11:40:10 +01:00
block.h
bus.c
bus.h
card.h
core.c mmc: core: Turn off CQE before sending commands 2017-08-30 15:03:33 +02:00
core.h mmc: core: Move mmc_start_areq() declaration 2017-08-30 15:03:53 +02:00
debugfs.c mmc: debugfs: Move block debugfs into block module 2017-08-30 15:03:39 +02:00
host.c mmc: core: Add mmc_retune_hold_now() 2017-08-30 14:02:01 +02:00
host.h mmc: core: Add mmc_retune_hold_now() 2017-08-30 14:02:01 +02:00
Kconfig mmc: core: Delete bounce buffer Kconfig option 2017-06-20 10:30:17 +02:00
Makefile
mmc.c mmc: core: add driver strength selection when selecting hs400es 2017-10-02 10:11:22 +02:00
mmc_ops.c mmc: ops: export mmc_get_status() 2017-08-30 15:03:39 +02:00
mmc_ops.h mmc: core: Re-factor code for sending CID 2017-06-20 10:30:45 +02:00
mmc_test.c mmc: test: reduce stack usage in mmc_test_nonblock_transfer 2017-08-30 15:03:37 +02:00
pwrseq.c
pwrseq.h
pwrseq_emmc.c
pwrseq_sd8787.c
pwrseq_simple.c
queue.c mmc: Delete bounce buffer handling 2017-10-04 10:22:55 +02:00
queue.h mmc: block: Convert RPMB to a character device 2017-10-30 11:40:10 +01:00
quirks.h
sd.c mmc: core: correct taac parameter according to the specification 2017-08-30 14:01:46 +02:00
sd.h
sd_ops.c
sd_ops.h
sdio.c mmc: sdio: Keep card runtime resumed while adding function devices 2017-06-20 10:30:39 +02:00
sdio_bus.c
sdio_bus.h
sdio_cis.c
sdio_cis.h
sdio_io.c
sdio_irq.c mmc: sdio: Add API to manage SDIO IRQs from a workqueue 2017-06-20 10:30:11 +02:00
sdio_ops.c
sdio_ops.h mmc: sdio: Add API to manage SDIO IRQs from a workqueue 2017-06-20 10:30:11 +02:00
sdio_uart.c
slot-gpio.c mmc: slot-gpio: Add support to enable irq wake on cd_irq 2017-06-20 10:30:49 +02:00
slot-gpio.h