Commit 6139281a6473334351c8776643478c0b0e208342

Authored by Simon Glass
1 parent e7017a3c7d

dm: blk: Allow finding block devices without probing

Sometimes it is useful to be able to find a block device without also
probing it. Add a function for this as well as the associated test.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 3 changed files with 48 additions and 3 deletions Side-by-side Diff

drivers/block/blk-uclass.c
... ... @@ -363,7 +363,7 @@
363 363 } while (1);
364 364 }
365 365  
366   -int blk_get_device(int if_type, int devnum, struct udevice **devp)
  366 +int blk_find_device(int if_type, int devnum, struct udevice **devp)
367 367 {
368 368 struct uclass *uc;
369 369 struct udevice *dev;
370 370  
... ... @@ -379,11 +379,22 @@
379 379 if_type, devnum, dev->name, desc->if_type, desc->devnum);
380 380 if (desc->if_type == if_type && desc->devnum == devnum) {
381 381 *devp = dev;
382   - return device_probe(dev);
  382 + return 0;
383 383 }
384 384 }
385 385  
386 386 return -ENODEV;
  387 +}
  388 +
  389 +int blk_get_device(int if_type, int devnum, struct udevice **devp)
  390 +{
  391 + int ret;
  392 +
  393 + ret = blk_find_device(if_type, devnum, devp);
  394 + if (ret)
  395 + return ret;
  396 +
  397 + return device_probe(*devp);
387 398 }
388 399  
389 400 unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start,
... ... @@ -253,12 +253,25 @@
253 253 lbaint_t blkcnt);
254 254  
255 255 /**
  256 + * blk_find_device() - Find a block device
  257 + *
  258 + * This function does not activate the device. The device will be returned
  259 + * whether or not it is activated.
  260 + *
  261 + * @if_type: Interface type (enum if_type_t)
  262 + * @devnum: Device number (specific to each interface type)
  263 + * @devp: the device, if found
  264 + * @return 0 if found, -ENODEV if no device found, or other -ve error value
  265 + */
  266 +int blk_find_device(int if_type, int devnum, struct udevice **devp);
  267 +
  268 +/**
256 269 * blk_get_device() - Find and probe a block device ready for use
257 270 *
258 271 * @if_type: Interface type (enum if_type_t)
259 272 * @devnum: Device number (specific to each interface type)
260 273 * @devp: the device, if found
261   - * @return - if found, -ENODEV if no device found, or other -ve error value
  274 + * @return 0 if found, -ENODEV if no device found, or other -ve error value
262 275 */
263 276 int blk_get_device(int if_type, int devnum, struct udevice **devp);
264 277  
... ... @@ -94,4 +94,25 @@
94 94 return 0;
95 95 }
96 96 DM_TEST(dm_test_blk_usb, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  97 +
  98 +/* Test that we can find block devices without probing them */
  99 +static int dm_test_blk_find(struct unit_test_state *uts)
  100 +{
  101 + struct udevice *blk, *dev;
  102 +
  103 + ut_assertok(blk_create_device(gd->dm_root, "sandbox_host_blk", "test",
  104 + IF_TYPE_HOST, 1, 512, 1024, &blk));
  105 + ut_asserteq(-ENODEV, blk_find_device(IF_TYPE_HOST, 0, &dev));
  106 + ut_assertok(blk_find_device(IF_TYPE_HOST, 1, &dev));
  107 + ut_asserteq_ptr(blk, dev);
  108 + ut_asserteq(false, device_active(dev));
  109 +
  110 + /* Now activate it */
  111 + ut_assertok(blk_get_device(IF_TYPE_HOST, 1, &dev));
  112 + ut_asserteq_ptr(blk, dev);
  113 + ut_asserteq(true, device_active(dev));
  114 +
  115 + return 0;
  116 +}
  117 +DM_TEST(dm_test_blk_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);