1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2020 EPAM Systems Inc.
8 #include <dm/device-internal.h>
10 #define DRV_NAME "pvblock"
11 #define DRV_NAME_BLK "pvblock_blk"
17 static int init_blkfront(unsigned int devid, struct blkfront_dev *dev)
22 static void shutdown_blkfront(struct blkfront_dev *dev)
26 ulong pvblock_blk_read(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
32 ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
38 static int pvblock_blk_bind(struct udevice *udev)
43 static int pvblock_blk_probe(struct udevice *udev)
45 struct blkfront_dev *blk_dev = dev_get_priv(udev);
48 ret = init_blkfront(0, blk_dev);
54 static int pvblock_blk_remove(struct udevice *udev)
56 struct blkfront_dev *blk_dev = dev_get_priv(udev);
58 shutdown_blkfront(blk_dev);
62 static const struct blk_ops pvblock_blk_ops = {
63 .read = pvblock_blk_read,
64 .write = pvblock_blk_write,
67 U_BOOT_DRIVER(pvblock_blk) = {
70 .ops = &pvblock_blk_ops,
71 .bind = pvblock_blk_bind,
72 .probe = pvblock_blk_probe,
73 .remove = pvblock_blk_remove,
74 .priv_auto_alloc_size = sizeof(struct blkfront_dev),
75 .flags = DM_FLAG_OS_PREPARE,
78 /*******************************************************************************
79 * Para-virtual block device class
80 *******************************************************************************/
82 void pvblock_init(void)
84 struct driver_info info;
90 * At this point Xen drivers have already initialized,
91 * so we can instantiate the class driver and enumerate
92 * virtual block devices.
95 ret = device_bind_by_name(gd->dm_root, false, &info, &udev);
97 printf("Failed to bind " DRV_NAME ", ret: %d\n", ret);
99 /* Bootstrap virtual block devices class driver */
100 ret = uclass_get(UCLASS_PVBLOCK, &uc);
103 uclass_foreach_dev_probe(UCLASS_PVBLOCK, udev);
106 static int pvblock_probe(struct udevice *udev)
111 U_BOOT_DRIVER(pvblock_drv) = {
113 .id = UCLASS_PVBLOCK,
114 .probe = pvblock_probe,
117 UCLASS_DRIVER(pvblock) = {
119 .id = UCLASS_PVBLOCK,