blob: d2b616bb63bd9f755721ae6fb08901d09e710169 [file] [log] [blame]
Anastasiia Lukianenko722bc5b2020-08-06 12:42:55 +03001// 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
13struct blkfront_dev {
14 char dummy;
15};
16
17static int init_blkfront(unsigned int devid, struct blkfront_dev *dev)
18{
19 return 0;
20}
21
22static void shutdown_blkfront(struct blkfront_dev *dev)
23{
24}
25
26ulong pvblock_blk_read(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
27 void *buffer)
28{
29 return 0;
30}
31
32ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
33 const void *buffer)
34{
35 return 0;
36}
37
38static int pvblock_blk_bind(struct udevice *udev)
39{
40 return 0;
41}
42
43static 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
54static 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
62static const struct blk_ops pvblock_blk_ops = {
63 .read = pvblock_blk_read,
64 .write = pvblock_blk_write,
65};
66
67U_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
82void 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
106static int pvblock_probe(struct udevice *udev)
107{
108 return 0;
109}
110
111U_BOOT_DRIVER(pvblock_drv) = {
112 .name = DRV_NAME,
113 .id = UCLASS_PVBLOCK,
114 .probe = pvblock_probe,
115};
116
117UCLASS_DRIVER(pvblock) = {
118 .name = DRV_NAME,
119 .id = UCLASS_PVBLOCK,
120};