pvblock.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2020 EPAM Systems Inc.
  4. */
  5. #include <blk.h>
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <dm/device-internal.h>
  9. #define DRV_NAME "pvblock"
  10. #define DRV_NAME_BLK "pvblock_blk"
  11. struct blkfront_dev {
  12. char dummy;
  13. };
  14. static int init_blkfront(unsigned int devid, struct blkfront_dev *dev)
  15. {
  16. return 0;
  17. }
  18. static void shutdown_blkfront(struct blkfront_dev *dev)
  19. {
  20. }
  21. ulong pvblock_blk_read(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
  22. void *buffer)
  23. {
  24. return 0;
  25. }
  26. ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
  27. const void *buffer)
  28. {
  29. return 0;
  30. }
  31. static int pvblock_blk_bind(struct udevice *udev)
  32. {
  33. return 0;
  34. }
  35. static int pvblock_blk_probe(struct udevice *udev)
  36. {
  37. struct blkfront_dev *blk_dev = dev_get_priv(udev);
  38. int ret;
  39. ret = init_blkfront(0, blk_dev);
  40. if (ret < 0)
  41. return ret;
  42. return 0;
  43. }
  44. static int pvblock_blk_remove(struct udevice *udev)
  45. {
  46. struct blkfront_dev *blk_dev = dev_get_priv(udev);
  47. shutdown_blkfront(blk_dev);
  48. return 0;
  49. }
  50. static const struct blk_ops pvblock_blk_ops = {
  51. .read = pvblock_blk_read,
  52. .write = pvblock_blk_write,
  53. };
  54. U_BOOT_DRIVER(pvblock_blk) = {
  55. .name = DRV_NAME_BLK,
  56. .id = UCLASS_BLK,
  57. .ops = &pvblock_blk_ops,
  58. .bind = pvblock_blk_bind,
  59. .probe = pvblock_blk_probe,
  60. .remove = pvblock_blk_remove,
  61. .priv_auto_alloc_size = sizeof(struct blkfront_dev),
  62. .flags = DM_FLAG_OS_PREPARE,
  63. };
  64. /*******************************************************************************
  65. * Para-virtual block device class
  66. *******************************************************************************/
  67. void pvblock_init(void)
  68. {
  69. struct driver_info info;
  70. struct udevice *udev;
  71. struct uclass *uc;
  72. int ret;
  73. /*
  74. * At this point Xen drivers have already initialized,
  75. * so we can instantiate the class driver and enumerate
  76. * virtual block devices.
  77. */
  78. info.name = DRV_NAME;
  79. ret = device_bind_by_name(gd->dm_root, false, &info, &udev);
  80. if (ret < 0)
  81. printf("Failed to bind " DRV_NAME ", ret: %d\n", ret);
  82. /* Bootstrap virtual block devices class driver */
  83. ret = uclass_get(UCLASS_PVBLOCK, &uc);
  84. if (ret)
  85. return;
  86. uclass_foreach_dev_probe(UCLASS_PVBLOCK, udev);
  87. }
  88. static int pvblock_probe(struct udevice *udev)
  89. {
  90. return 0;
  91. }
  92. U_BOOT_DRIVER(pvblock_drv) = {
  93. .name = DRV_NAME,
  94. .id = UCLASS_PVBLOCK,
  95. .probe = pvblock_probe,
  96. };
  97. UCLASS_DRIVER(pvblock) = {
  98. .name = DRV_NAME,
  99. .id = UCLASS_PVBLOCK,
  100. };