Anastasiia Lukianenko | 722bc5b | 2020-08-06 12:42:55 +0300 | [diff] [blame^] | 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 | |
| 10 | #define DRV_NAME "pvblock" |
| 11 | #define DRV_NAME_BLK "pvblock_blk" |
| 12 | |
| 13 | struct blkfront_dev { |
| 14 | char dummy; |
| 15 | }; |
| 16 | |
| 17 | static int init_blkfront(unsigned int devid, struct blkfront_dev *dev) |
| 18 | { |
| 19 | return 0; |
| 20 | } |
| 21 | |
| 22 | static void shutdown_blkfront(struct blkfront_dev *dev) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | ulong pvblock_blk_read(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt, |
| 27 | void *buffer) |
| 28 | { |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt, |
| 33 | const void *buffer) |
| 34 | { |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static int pvblock_blk_bind(struct udevice *udev) |
| 39 | { |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static int pvblock_blk_probe(struct udevice *udev) |
| 44 | { |
| 45 | struct blkfront_dev *blk_dev = dev_get_priv(udev); |
| 46 | int ret; |
| 47 | |
| 48 | ret = init_blkfront(0, blk_dev); |
| 49 | if (ret < 0) |
| 50 | return ret; |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static int pvblock_blk_remove(struct udevice *udev) |
| 55 | { |
| 56 | struct blkfront_dev *blk_dev = dev_get_priv(udev); |
| 57 | |
| 58 | shutdown_blkfront(blk_dev); |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | static const struct blk_ops pvblock_blk_ops = { |
| 63 | .read = pvblock_blk_read, |
| 64 | .write = pvblock_blk_write, |
| 65 | }; |
| 66 | |
| 67 | U_BOOT_DRIVER(pvblock_blk) = { |
| 68 | .name = DRV_NAME_BLK, |
| 69 | .id = UCLASS_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, |
| 76 | }; |
| 77 | |
| 78 | /******************************************************************************* |
| 79 | * Para-virtual block device class |
| 80 | *******************************************************************************/ |
| 81 | |
| 82 | void pvblock_init(void) |
| 83 | { |
| 84 | struct driver_info info; |
| 85 | struct udevice *udev; |
| 86 | struct uclass *uc; |
| 87 | int ret; |
| 88 | |
| 89 | /* |
| 90 | * At this point Xen drivers have already initialized, |
| 91 | * so we can instantiate the class driver and enumerate |
| 92 | * virtual block devices. |
| 93 | */ |
| 94 | info.name = DRV_NAME; |
| 95 | ret = device_bind_by_name(gd->dm_root, false, &info, &udev); |
| 96 | if (ret < 0) |
| 97 | printf("Failed to bind " DRV_NAME ", ret: %d\n", ret); |
| 98 | |
| 99 | /* Bootstrap virtual block devices class driver */ |
| 100 | ret = uclass_get(UCLASS_PVBLOCK, &uc); |
| 101 | if (ret) |
| 102 | return; |
| 103 | uclass_foreach_dev_probe(UCLASS_PVBLOCK, udev); |
| 104 | } |
| 105 | |
| 106 | static int pvblock_probe(struct udevice *udev) |
| 107 | { |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | U_BOOT_DRIVER(pvblock_drv) = { |
| 112 | .name = DRV_NAME, |
| 113 | .id = UCLASS_PVBLOCK, |
| 114 | .probe = pvblock_probe, |
| 115 | }; |
| 116 | |
| 117 | UCLASS_DRIVER(pvblock) = { |
| 118 | .name = DRV_NAME, |
| 119 | .id = UCLASS_PVBLOCK, |
| 120 | }; |