dm: mmc: Tidy up use of block devices
Subsystems (2)
cover dm: mmc: Tidy up use of block devices
A recent series added a patch to avoid probing block devices in find_mmc_device(). This is because callers should obtain the block device itself, not the MMC device. But for now the environment code has not been converted.
The patch caused problems on some boards so was dropped.
This series reinstates that patch, but ensures that the block device is probed first.
Simon Glass (3):
dm: blk: Add a way to obtain a block device from its parent
dm: mmc: Ensure that block device is probed
dm: mmc: Avoid probing block devices in find_mmc_device()
common/env_mmc.c | 7 ++++++- drivers/block/blk-uclass.c | 26 ++++++++++++++++++++++++++ drivers/mmc/mmc-uclass.c | 6 ++++-- include/blk.h | 7 +++++++ test/dm/blk.c | 18 ++++++++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-)
Signature · 1 line
2.13.0.219.gdb65acc882-goog
PATCH 1/3 dm: blk: Add a way to obtain a block device from its parent
Many devices support a child block device (e.g. MMC, USB). Add a convenient way to get this device given the parent device.
---
drivers/block/blk-uclass.c | 26 ++++++++++++++++++++++++++ include/blk.h | 7 +++++++ test/dm/blk.c | 18 ++++++++++++++++++ 3 files changed, 51 insertions(+)
drivers/block/blk-uclass.c +26 -0
@@ -453,6 +453,32 @@ int blk_prepare_device(struct udevice *dev)return 0 ; } +int blk_get_from_parent (struct udevice *parent,struct udevice **devp) +{ +struct udevice *dev; +enum uclass_id id; +int ret; + +device_find_first_child (parent, &dev); +if (!dev) { +debug ("%s: No block device found for parent '%s'\n" , __func__, + parent->name); +return -ENODEV ; + } + id =device_get_uclass_id (dev); +if (id !=UCLASS_BLK ) { +debug ("%s: Incorrect uclass %s for block device '%s'\n" , + __func__,uclass_get_name (id), dev->name); +return -ENOTBLK ; + } + ret =device_probe (dev); +if (ret) +return ret; + *devp = dev; + +return 0 ; +} +int blk_find_max_devnum (enum if_type if_type) {struct udevice *dev;
include/blk.h +7 -0
@@ -616,4 +616,11 @@ ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,*/ int blk_select_hwpart_devnum (enum if_type if_type,int devnum,int hwpart); +/** +* blk_get_from_parent() - obtain a block device by looking up its parent +* +* All devices with +*/ +int blk_get_from_parent (struct udevice *parent,struct udevice **devp); +#endif
test/dm/blk.c +18 -0
@@ -150,3 +150,21 @@ static int dm_test_blk_devnum(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_blk_devnum,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test that we can get a block from its parent */ +static int dm_test_blk_get_from_parent (struct unit_test_state *uts) +{ +struct udevice *dev, *blk; + +ut_assertok (uclass_get_device (UCLASS_MMC ,0 , &dev)); +ut_assertok (blk_get_from_parent (dev, &blk)); + +ut_assertok (uclass_get_device (UCLASS_I2C ,0 , &dev)); +ut_asserteq (-ENOTBLK ,blk_get_from_parent (dev, &blk)); + +ut_assertok (uclass_get_device (UCLASS_GPIO ,0 , &dev)); +ut_asserteq (-ENODEV ,blk_get_from_parent (dev, &blk)); + +return 0 ; +} +DM_TEST (dm_test_blk_get_from_parent,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.13.0.219.gdb65acc882-goog
PATCH 1/3 dm: blk: Add a way to obtain a block device from its parent
Quoted 4 lines · Simon Glass
Many devices support a child block device (e.g. MMC, USB). Add a convenient way to get this device given the parent device.
Signed-off-by Simon Glass <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170528/c4254653/attachment.sig>
PATCH 1/3 dm: blk: Add a way to obtain a block device from its parent
In reply to Simon GlassHi Simon,
Quoted 53 lines · Simon Glass
Many devices support a child block device (e.g. MMC, USB). Add a convenient way to get this device given the parent device.
Signed-off-by Simon Glass <[email protected]>---
drivers/block/blk-uclass.c | 26 ++++++++++++++++++++++++++ include/blk.h | 7 +++++++ test/dm/blk.c | 18 ++++++++++++++++++ 3 files changed, 51 insertions(+)drivers/block/blk-uclass.c +26
-0@@ -453,6 +453,32 @@ int blk_prepare_device(struct udevice *dev)return 0 ; } +int blk_get_from_parent (struct udevice *parent,struct udevice **devp) +{ +struct udevice *dev; +enum uclass_id id; +int ret; + +device_find_first_child (parent, &dev); +if (!dev) { +debug ("%s: No block device found for parent '%s'\n" , __func__, + parent->name); +return -ENODEV ; + } + id =device_get_uclass_id (dev); +if (id !=UCLASS_BLK ) { +debug ("%s: Incorrect uclass %s for block device '%s'\n" , + __func__,uclass_get_name (id), dev->name); +return -ENOTBLK ; + } + ret =device_probe (dev); +if (ret) +return ret; + *devp = dev; + +return 0 ; +} +int blk_find_max_devnum (enum if_type if_type) {struct udevice *dev;include/blk.h +0
-0
include/blk.h ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start, · line 624
Quoted 9 lines
include/blk.h +6
-0@@ -616,4 +616,11 @@ ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,*/ int blk_select_hwpart_devnum (enum if_type if_type,int devnum,int hwpart); +/** +* blk_get_from_parent() - obtain a block device by looking up its parent +* +* All devices with +*/ +int blk_get_from_parent (struct udevice *parent,struct udevice **devp);
Don't need to consider whether CONFIG_BLK is defined or not? blk_get_from_parent() is declared in blk-uclass.c
Best Regards,
Jaehoon Chung
Quoted 29 lines
include/blk.h +1
-0+#endif test/dm/blk.c +18
-0@@ -150,3 +150,21 @@ static int dm_test_blk_devnum(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_blk_devnum,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test that we can get a block from its parent */ +static int dm_test_blk_get_from_parent (struct unit_test_state *uts) +{ +struct udevice *dev, *blk; + +ut_assertok (uclass_get_device (UCLASS_MMC ,0 , &dev)); +ut_assertok (blk_get_from_parent (dev, &blk)); + +ut_assertok (uclass_get_device (UCLASS_I2C ,0 , &dev)); +ut_asserteq (-ENOTBLK ,blk_get_from_parent (dev, &blk)); + +ut_assertok (uclass_get_device (UCLASS_GPIO ,0 , &dev)); +ut_asserteq (-ENODEV ,blk_get_from_parent (dev, &blk)); + +return 0 ; +} +DM_TEST (dm_test_blk_get_from_parent,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
PATCH 1/3 dm: blk: Add a way to obtain a block device from its parent
Hi Jaehoon,
Quoted 59 lines · Jaehoon Chung
Hi Simon,
Quoted 56 lines · Simon Glass
Many devices support a child block device (e.g. MMC, USB). Add a convenient way to get this device given the parent device.
Signed-off-by Simon Glass <[email protected]>---
drivers/block/blk-uclass.c | 26 ++++++++++++++++++++++++++ include/blk.h | 7 +++++++ test/dm/blk.c | 18 ++++++++++++++++++ 3 files changed, 51 insertions(+)drivers/block/blk-uclass.c +26
-0@@ -453,6 +453,32 @@ int blk_prepare_device(struct udevice *dev)return 0 ; } +int blk_get_from_parent (struct udevice *parent,struct udevice **devp) +{ +struct udevice *dev; +enum uclass_id id; +int ret; + +device_find_first_child (parent, &dev); +if (!dev) { +debug ("%s: No block device found for parent '%s'\n" , __func__, + parent->name); +return -ENODEV ; + } + id =device_get_uclass_id (dev); +if (id !=UCLASS_BLK ) { +debug ("%s: Incorrect uclass %s for block device '%s'\n" , + __func__,uclass_get_name (id), dev->name); +return -ENOTBLK ; + } + ret =device_probe (dev); +if (ret) +return ret; + *devp = dev; + +return 0 ; +} +int blk_find_max_devnum (enum if_type if_type) {struct udevice *dev;include/blk.h +0
-0@@ -616,4 +616,11 @@ ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,*/ int blk_select_hwpart_devnum (enum if_type if_type,int devnum,int hwpart);
Quoted 9 lines
include/blk.h ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start, · line 624
Quoted 6 lines
include/blk.h +6
-0+/** +* blk_get_from_parent() - obtain a block device by looking up its parent +* +* All devices with +*/ +int blk_get_from_parent (struct udevice *parent,struct udevice **devp);Don't need to consider whether
CONFIG_BLKis defined or not?blk_get_from_parent()is declared inblk-uclass.c
Well in that case this function will not be called, so I think it is OK.
Quoted 3 lines
Best Regards,
Jaehoon Chung
- Simon
PATCH 1/3 dm: blk: Add a way to obtain a block device from its parent
Quoted 72 lines · Simon Glass
Hi Jaehoon,
Quoted 59 lines · Jaehoon Chung
Hi Simon,
Quoted 56 lines · Simon Glass
Many devices support a child block device (e.g. MMC, USB). Add a convenient way to get this device given the parent device.
Signed-off-by Simon Glass <[email protected]>---
drivers/block/blk-uclass.c | 26 ++++++++++++++++++++++++++ include/blk.h | 7 +++++++ test/dm/blk.c | 18 ++++++++++++++++++ 3 files changed, 51 insertions(+)drivers/block/blk-uclass.c +26
-0@@ -453,6 +453,32 @@ int blk_prepare_device(struct udevice *dev)return 0 ; } +int blk_get_from_parent (struct udevice *parent,struct udevice **devp) +{ +struct udevice *dev; +enum uclass_id id; +int ret; + +device_find_first_child (parent, &dev); +if (!dev) { +debug ("%s: No block device found for parent '%s'\n" , __func__, + parent->name); +return -ENODEV ; + } + id =device_get_uclass_id (dev); +if (id !=UCLASS_BLK ) { +debug ("%s: Incorrect uclass %s for block device '%s'\n" , + __func__,uclass_get_name (id), dev->name); +return -ENOTBLK ; + } + ret =device_probe (dev); +if (ret) +return ret; + *devp = dev; + +return 0 ; +} +int blk_find_max_devnum (enum if_type if_type) {struct udevice *dev;include/blk.h +0
-0@@ -616,4 +616,11 @@ ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,*/ int blk_select_hwpart_devnum (enum if_type if_type,int devnum,int hwpart);Quoted 9 lines
include/blk.h ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start, · line 624
Quoted 6 lines
include/blk.h +6
-0+/** +* blk_get_from_parent() - obtain a block device by looking up its parent +* +* All devices with +*/ +int blk_get_from_parent (struct udevice *parent,struct udevice **devp);Don't need to consider whether
CONFIG_BLKis defined or not?blk_get_from_parent()is declared inblk-uclass.c
Quoted 1 line
Well in that case this function will not be called, so I think it is OK.
include/blk.h:624:32: warning: 'struct udevice' declared inside parameter list will not be visible outside of this definition or declaration
int blk_get_from_parent(struct udevice *parent, struct udevice **devp);
Plz, check this.. :)
Best Regards,
Jaehoon Chung
Quoted 9 lines
Quoted 4 lines
Best Regards,
Jaehoon Chung- Simon
PATCH 1/3 dm: blk: Add a way to obtain a block device from its parent
Hi Jaehoon,
Quoted 73 lines · Jaehoon Chung
Quoted 72 lines · Simon Glass
Hi Jaehoon,
Quoted 68 lines · Jaehoon Chung
Hi Simon,
Quoted 53 lines · Simon Glass
Many devices support a child block device (e.g. MMC, USB). Add a convenient way to get this device given the parent device.
Signed-off-by Simon Glass <[email protected]>---
drivers/block/blk-uclass.c | 26 ++++++++++++++++++++++++++ include/blk.h | 7 +++++++ test/dm/blk.c | 18 ++++++++++++++++++ 3 files changed, 51 insertions(+)drivers/block/blk-uclass.c +26
-0@@ -453,6 +453,32 @@ int blk_prepare_device(struct udevice *dev)return 0 ; } +int blk_get_from_parent (struct udevice *parent,struct udevice **devp) +{ +struct udevice *dev; +enum uclass_id id; +int ret; + +device_find_first_child (parent, &dev); +if (!dev) { +debug ("%s: No block device found for parent '%s'\n" , __func__, + parent->name); +return -ENODEV ; + } + id =device_get_uclass_id (dev); +if (id !=UCLASS_BLK ) { +debug ("%s: Incorrect uclass %s for block device '%s'\n" , + __func__,uclass_get_name (id), dev->name); +return -ENOTBLK ; + } + ret =device_probe (dev); +if (ret) +return ret; + *devp = dev; + +return 0 ; +} +int blk_find_max_devnum (enum if_type if_type) {struct udevice *dev;include/blk.h +0
-0include/blk.h ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start, · line 624
Quoted 9 lines
include/blk.h +6
-0@@ -616,4 +616,11 @@ ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,*/ int blk_select_hwpart_devnum (enum if_type if_type,int devnum,int hwpart); +/** +* blk_get_from_parent() - obtain a block device by looking up its parent +* +* All devices with +*/ +int blk_get_from_parent (struct udevice *parent,struct udevice **devp);Don't need to consider whether
CONFIG_BLKis defined or not?blk_get_from_parent()is declared inblk-uclass.c
Quoted 6 lines
Quoted 1 line
Well in that case this function will not be called, so I think it is OK.
include/blk.h:624:32: warning: 'struct udevice' declared inside parameter list will not be visible outside of this definition or declaration
intblk_get_from_parent(struct udevice *parent, struct udevice **devp);Plz, check this.. :)
Which board is this, please?
Regards,
Simon
PATCH 2/3 dm: mmc: Ensure that block device is probed
In reply to Simon GlassMake sure that we probe the block device before using it when reading the environment.
---
common/env_mmc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
common/env_mmc.c +6 -1
@@ -98,7 +98,12 @@ static const char *init_mmc_for_env(struct mmc *mmc)if (!mmc)return "!No MMC card found" ; -#ifndef CONFIG_BLK +#ifdef CONFIG_BLK +struct udevice *dev; + +if (blk_get_from_parent (mmc->dev, &dev)) +return "!No block device" ; +#else if (mmc_init (mmc))return "!MMC init failed" ;#endif
Signature · 1 line
2.13.0.219.gdb65acc882-goog
PATCH 2/3 dm: mmc: Ensure that block device is probed
Quoted 4 lines · Simon Glass
Make sure that we probe the block device before using it when reading the environment.
Signed-off-by Simon Glass <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170528/6e6f48ba/attachment.sig>
PATCH 3/3 dm: mmc: Avoid probing block devices in find_mmc_device()
In reply to Simon GlassWe do not need to probe the block device here, so avoid doing so. The MMC device itself must be active, but the block device can come later.
---
drivers/mmc/mmc-uclass.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/mmc/mmc-uclass.c +4 -2
@@ -97,7 +97,7 @@ struct mmc *find_mmc_device(int dev_num)struct udevice *dev, *mmc_dev;int ret; - ret =blk_get_device (IF_TYPE_MMC , dev_num, &dev); + ret =blk_find_device (IF_TYPE_MMC , dev_num, &dev);if (ret) {#if !defined(CONFIG_SPL_BUILD ) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT )
@@ -108,7 +108,9 @@ struct mmc *find_mmc_device(int dev_num) mmc_dev =dev_get_parent (dev); -return mmc_get_mmc_dev (mmc_dev); +struct mmc *mmc =mmc_get_mmc_dev (mmc_dev); + +return mmc; }int get_mmc_num (void )
Signature · 1 line
2.13.0.219.gdb65acc882-goog
PATCH 3/3 dm: mmc: Avoid probing block devices in find_mmc_device()
Quoted 23 lines · Simon Glass
We do not need to probe the block device here, so avoid doing so. The MMC device itself must be active, but the block device can come later.
Signed-off-by Simon Glass <[email protected]>---
drivers/mmc/mmc-uclass.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/mmc/mmc-uclass.c +1
-1@@ -97,7 +97,7 @@ struct mmc *find_mmc_device(int dev_num)struct udevice *dev, *mmc_dev;int ret; - ret =blk_get_device (IF_TYPE_MMC , dev_num, &dev); + ret =blk_find_device (IF_TYPE_MMC , dev_num, &dev);if (ret) {#if !defined(CONFIG_SPL_BUILD ) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT )
drivers/mmc/mmc-uclass.c struct mmc *find_mmc_device(int dev_num) · line 113
Quoted 7 lines
drivers/mmc/mmc-uclass.c +3
-1@@ -108,7 +108,9 @@ struct mmc *find_mmc_device(int dev_num) mmc_dev =dev_get_parent (dev); -return mmc_get_mmc_dev (mmc_dev); +struct mmc *mmc =mmc_get_mmc_dev (mmc_dev); + +return mmc;
We should declare new variables at the top of the function here, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170528/b4186341/attachment.sig>
cover dm: mmc: Tidy up use of block devices
In reply to Simon GlassHi Simon,
Quoted 10 lines · Simon Glass
A recent series added a patch to avoid probing block devices in
find_mmc_device(). This is because callers should obtain the block device itself, not the MMC device. But for now the environment code has not been converted.The patch caused problems on some boards so was dropped.
This series reinstates that patch, but ensures that the block device is probed first.
Is there a patch before applying these patches?
When i tried to apply patches from patchwork, it doesn't apply.
Best Regards,
Jaehoon Chung
Quoted 13 lines
Simon Glass (3):
dm: blk: Add a way to obtain a block device from its parent
dm: mmc: Ensure that block device is probed
dm: mmc: Avoid probing block devices infind_mmc_device()common/env_mmc.c | 7 ++++++- drivers/block/blk-uclass.c | 26 ++++++++++++++++++++++++++ drivers/mmc/mmc-uclass.c | 6 ++++-- include/blk.h | 7 +++++++ test/dm/blk.c | 18 ++++++++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-)
cover dm: mmc: Tidy up use of block devices
Hi Jaehoon,
Quoted 14 lines · Jaehoon Chung
Hi Simon,
Quoted 10 lines · Simon Glass
A recent series added a patch to avoid probing block devices in
find_mmc_device(). This is because callers should obtain the block device itself, not the MMC device. But for now the environment code has not been converted.The patch caused problems on some boards so was dropped.
This series reinstates that patch, but ensures that the block device is probed first.
Quoted 20 lines
Is there a patch before applying these patches?
When i tried to apply patches from patchwork, it doesn't apply.Best Regards,
Jaehoon ChungQuoted 13 lines
Simon Glass (3):
dm: blk: Add a way to obtain a block device from its parent
dm: mmc: Ensure that block device is probed
dm: mmc: Avoid probing block devices infind_mmc_device()common/env_mmc.c | 7 ++++++- drivers/block/blk-uclass.c | 26 ++++++++++++++++++++++++++ drivers/mmc/mmc-uclass.c | 6 ++++-- include/blk.h | 7 +++++++ test/dm/blk.c | 18 ++++++++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-)
Yes - it is at u-boot-dm/mmc-working. I think the prerequisites will land in master tonight.
Regards,
Simon