diff mbox series

[v1,2/3] mmc: block: Add mmc_bdev_to_card() helper

Message ID 20200224231841.26550-3-digetx@gmail.com (mailing list archive)
State New, archived
Headers show
Series Introduce NVIDIA Tegra Partition Table | expand

Commit Message

Dmitry Osipenko Feb. 24, 2020, 11:18 p.m. UTC
NVIDIA Tegra Partition Table takes into account MMC card's BOOT_SIZE_MULT
parameter, and thus, the partition parser needs to retrieve that EXT_CSD
value from the block device. This patch introduces new helper which takes
block device for the input argument and returns corresponding MMC card.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/mmc/core/block.c | 14 ++++++++++++++
 include/linux/mmc/card.h |  3 +++
 2 files changed, 17 insertions(+)

Comments

Ulf Hansson Feb. 25, 2020, 2:53 p.m. UTC | #1
On Tue, 25 Feb 2020 at 00:22, Dmitry Osipenko <digetx@gmail.com> wrote:
>
> NVIDIA Tegra Partition Table takes into account MMC card's BOOT_SIZE_MULT
> parameter, and thus, the partition parser needs to retrieve that EXT_CSD
> value from the block device. This patch introduces new helper which takes
> block device for the input argument and returns corresponding MMC card.

Rather than returning the card, why not return the value you are
looking for instead? That sound more straightforward, but also allows
mmc core code to stay closer to the mmc core.

Kind regards
Uffe

>
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/mmc/core/block.c | 14 ++++++++++++++
>  include/linux/mmc/card.h |  3 +++
>  2 files changed, 17 insertions(+)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 663d87924e5e..5d853450c764 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -301,6 +301,20 @@ static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr,
>         return ret;
>  }
>
> +struct mmc_card *mmc_bdev_to_card(struct block_device *bdev)
> +{
> +       struct mmc_blk_data *md;
> +
> +       if (bdev->bd_disk->major != MMC_BLOCK_MAJOR)
> +               return NULL;
> +
> +       md = mmc_blk_get(bdev->bd_disk);
> +       if (!md)
> +               return NULL;
> +
> +       return md->queue.card;
> +}
> +
>  static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
>  {
>         struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
> diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
> index 90b1d83ce675..daccb0cc25f8 100644
> --- a/include/linux/mmc/card.h
> +++ b/include/linux/mmc/card.h
> @@ -7,6 +7,7 @@
>  #ifndef LINUX_MMC_CARD_H
>  #define LINUX_MMC_CARD_H
>
> +#include <linux/blkdev.h>
>  #include <linux/device.h>
>  #include <linux/mod_devicetable.h>
>
> @@ -324,4 +325,6 @@ bool mmc_card_is_blockaddr(struct mmc_card *card);
>  #define mmc_card_sd(c)         ((c)->type == MMC_TYPE_SD)
>  #define mmc_card_sdio(c)       ((c)->type == MMC_TYPE_SDIO)
>
> +struct mmc_card *mmc_bdev_to_card(struct block_device *bdev);
> +
>  #endif /* LINUX_MMC_CARD_H */
> --
> 2.24.0
>
Dmitry Osipenko Feb. 25, 2020, 3:46 p.m. UTC | #2
25.02.2020 17:53, Ulf Hansson пишет:
> On Tue, 25 Feb 2020 at 00:22, Dmitry Osipenko <digetx@gmail.com> wrote:
>>
>> NVIDIA Tegra Partition Table takes into account MMC card's BOOT_SIZE_MULT
>> parameter, and thus, the partition parser needs to retrieve that EXT_CSD
>> value from the block device. This patch introduces new helper which takes
>> block device for the input argument and returns corresponding MMC card.
> 
> Rather than returning the card, why not return the value you are
> looking for instead? That sound more straightforward, but also allows
> mmc core code to stay closer to the mmc core.

Please take a look at patch #3, in particular see the
tegra_partition_table_emmc_boot_offset(). We already need more than just
the BOOT_SIZE_MULT from the struct mmc_card, in the the v2 of this
series we will probably need even a bit more.

I'll adjust the commit's message of this patch in v2, saying that more
than BOOT_SIZE_MULT is needed from the struct mmc_card. Are you okay
with this variant?

----

BTW, do you have any idea how partition table scanning of MMC's boot0/1
partitions potentially could be implemented?

It's not uncommon for Tegra devices that partition table could reside in
one of the MMC's boot partitions (Nexus 7 is one example). For now I
don't see how the scanning could be implemented easily because all
boot0/boot1/main partitions are very separated from each other in the
kernel's MMC_BLOCK.

One potential hack that comes into my mind is that the boot0/1
partitions could be always registered before the main MMC partition and
then they always will be scanned first, i.e. before the main partition.
This will allow to read out partition table from the boot partitions and
stash it for the main.
kernel test robot Feb. 27, 2020, 12:40 a.m. UTC | #3
Hi Dmitry,

I love your patch! Yet something to improve:

[auto build test ERROR on block/for-next]
[also build test ERROR on tegra/for-next linus/master v5.6-rc3 next-20200226]
[cannot apply to ulf.hansson-mmc/next]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Dmitry-Osipenko/Introduce-NVIDIA-Tegra-Partition-Table/20200225-072610
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: m68k-randconfig-a001-20200227 (attached as .config)
compiler: m68k-linux-gcc (GCC) 7.5.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.5.0 make.cross ARCH=m68k 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/mmc/host/wbsd.c: In function 'wbsd_request_end':
   drivers/mmc/host/wbsd.c:210:14: error: implicit declaration of function 'claim_dma_lock'; did you mean 'can_do_mlock'? [-Werror=implicit-function-declaration]
      dmaflags = claim_dma_lock();
                 ^~~~~~~~~~~~~~
                 can_do_mlock
>> drivers/mmc/host/wbsd.c:213:3: error: implicit declaration of function 'release_dma_lock'; did you mean 'release_pages'? [-Werror=implicit-function-declaration]
      release_dma_lock(dmaflags);
      ^~~~~~~~~~~~~~~~
      release_pages
   cc1: some warnings being treated as errors

vim +213 drivers/mmc/host/wbsd.c

^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  201  
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  202  static void wbsd_request_end(struct wbsd_host *host, struct mmc_request *mrq)
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  203  {
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  204  	unsigned long dmaflags;
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  205  
cfa7f52164d6cd drivers/mmc/wbsd.c Pierre Ossman  2006-01-08  206  	if (host->dma >= 0) {
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  207  		/*
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  208  		 * Release ISA DMA controller.
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  209  		 */
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16 @210  		dmaflags = claim_dma_lock();
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  211  		disable_dma(host->dma);
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  212  		clear_dma_ff(host->dma);
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16 @213  		release_dma_lock(dmaflags);
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  214  
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  215  		/*
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  216  		 * Disable DMA on host.
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  217  		 */
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  218  		wbsd_write_index(host, WBSD_IDX_DMA, 0);
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  219  	}
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  220  
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  221  	host->mrq = NULL;
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  222  
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  223  	/*
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  224  	 * MMC layer might call back into the driver so first unlock.
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  225  	 */
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  226  	spin_unlock(&host->lock);
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  227  	mmc_request_done(host->mmc, mrq);
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  228  	spin_lock(&host->lock);
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  229  }
^1da177e4c3f41 drivers/mmc/wbsd.c Linus Torvalds 2005-04-16  230  

:::::: The code at line 213 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 663d87924e5e..5d853450c764 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -301,6 +301,20 @@  static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr,
 	return ret;
 }
 
+struct mmc_card *mmc_bdev_to_card(struct block_device *bdev)
+{
+	struct mmc_blk_data *md;
+
+	if (bdev->bd_disk->major != MMC_BLOCK_MAJOR)
+		return NULL;
+
+	md = mmc_blk_get(bdev->bd_disk);
+	if (!md)
+		return NULL;
+
+	return md->queue.card;
+}
+
 static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
 {
 	struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 90b1d83ce675..daccb0cc25f8 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -7,6 +7,7 @@ 
 #ifndef LINUX_MMC_CARD_H
 #define LINUX_MMC_CARD_H
 
+#include <linux/blkdev.h>
 #include <linux/device.h>
 #include <linux/mod_devicetable.h>
 
@@ -324,4 +325,6 @@  bool mmc_card_is_blockaddr(struct mmc_card *card);
 #define mmc_card_sd(c)		((c)->type == MMC_TYPE_SD)
 #define mmc_card_sdio(c)	((c)->type == MMC_TYPE_SDIO)
 
+struct mmc_card *mmc_bdev_to_card(struct block_device *bdev);
+
 #endif /* LINUX_MMC_CARD_H */