summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorAnastasiia Lukianenko <anastasiia_lukianenko@epam.com>2020-08-06 12:42:55 +0300
committerTom Rini <trini@konsulko.com>2020-08-14 15:18:30 -0400
commit722bc5b5d901eafb96e8530cc7cf3036bff398a4 (patch)
treedd7518078a82e91b14944d9136147e688e064992 /drivers
parentc850674ff74b1625c17a77a454acec0e9cc6ec36 (diff)
xen: pvblock: Add initial support for para-virtualized block driver
Add initial infrastructure for Xen para-virtualized block device. This includes compile-time configuration and the skeleton for the future driver implementation. Add new class UCLASS_PVBLOCK which is going to be a parent for virtual block devices. Add new interface type IF_TYPE_PVBLOCK. Implement basic driver setup by reading XenStore configuration. Signed-off-by: Andrii Anisov <andrii_anisov@epam.com> Signed-off-by: Anastasiia Lukianenko <anastasiia_lukianenko@epam.com> Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/block/blk-uclass.c2
-rw-r--r--drivers/xen/Kconfig10
-rw-r--r--drivers/xen/Makefile2
-rw-r--r--drivers/xen/pvblock.c120
5 files changed, 136 insertions, 0 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig
index 119e412849..613669cb38 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -136,6 +136,8 @@ source "drivers/w1-eeprom/Kconfig"
source "drivers/watchdog/Kconfig"
+source "drivers/xen/Kconfig"
+
config PHYS_TO_BUS
bool "Custom physical to bus address mapping"
help
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index b46a1ac8d2..2fb9f6b765 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -28,6 +28,7 @@ static const char *if_typename_str[IF_TYPE_COUNT] = {
[IF_TYPE_NVME] = "nvme",
[IF_TYPE_EFI] = "efi",
[IF_TYPE_VIRTIO] = "virtio",
+ [IF_TYPE_PVBLOCK] = "pvblock",
};
static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
@@ -43,6 +44,7 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
[IF_TYPE_NVME] = UCLASS_NVME,
[IF_TYPE_EFI] = UCLASS_EFI,
[IF_TYPE_VIRTIO] = UCLASS_VIRTIO,
+ [IF_TYPE_PVBLOCK] = UCLASS_PVBLOCK,
};
static enum if_type if_typename_to_iftype(const char *if_typename)
diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig
new file mode 100644
index 0000000000..6ad2a93668
--- /dev/null
+++ b/drivers/xen/Kconfig
@@ -0,0 +1,10 @@
+config PVBLOCK
+ bool "Xen para-virtualized block device"
+ depends on DM
+ select BLK
+ select HAVE_BLOCK_DEVICE
+ help
+ This driver implements the front-end of the Xen virtual
+ block device driver. It communicates with a back-end driver
+ in another domain which drives the actual block device.
+
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile
index 243b13277a..87157df69b 100644
--- a/drivers/xen/Makefile
+++ b/drivers/xen/Makefile
@@ -6,3 +6,5 @@ obj-y += hypervisor.o
obj-y += events.o
obj-y += xenbus.o
obj-y += gnttab.o
+
+obj-$(CONFIG_PVBLOCK) += pvblock.o
diff --git a/drivers/xen/pvblock.c b/drivers/xen/pvblock.c
new file mode 100644
index 0000000000..d2b616bb63
--- /dev/null
+++ b/drivers/xen/pvblock.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2020 EPAM Systems Inc.
+ */
+#include <blk.h>
+#include <common.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+
+#define DRV_NAME "pvblock"
+#define DRV_NAME_BLK "pvblock_blk"
+
+struct blkfront_dev {
+ char dummy;
+};
+
+static int init_blkfront(unsigned int devid, struct blkfront_dev *dev)
+{
+ return 0;
+}
+
+static void shutdown_blkfront(struct blkfront_dev *dev)
+{
+}
+
+ulong pvblock_blk_read(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
+ void *buffer)
+{
+ return 0;
+}
+
+ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
+ const void *buffer)
+{
+ return 0;
+}
+
+static int pvblock_blk_bind(struct udevice *udev)
+{
+ return 0;
+}
+
+static int pvblock_blk_probe(struct udevice *udev)
+{
+ struct blkfront_dev *blk_dev = dev_get_priv(udev);
+ int ret;
+
+ ret = init_blkfront(0, blk_dev);
+ if (ret < 0)
+ return ret;
+ return 0;
+}
+
+static int pvblock_blk_remove(struct udevice *udev)
+{
+ struct blkfront_dev *blk_dev = dev_get_priv(udev);
+
+ shutdown_blkfront(blk_dev);
+ return 0;
+}
+
+static const struct blk_ops pvblock_blk_ops = {
+ .read = pvblock_blk_read,
+ .write = pvblock_blk_write,
+};
+
+U_BOOT_DRIVER(pvblock_blk) = {
+ .name = DRV_NAME_BLK,
+ .id = UCLASS_BLK,
+ .ops = &pvblock_blk_ops,
+ .bind = pvblock_blk_bind,
+ .probe = pvblock_blk_probe,
+ .remove = pvblock_blk_remove,
+ .priv_auto_alloc_size = sizeof(struct blkfront_dev),
+ .flags = DM_FLAG_OS_PREPARE,
+};
+
+/*******************************************************************************
+ * Para-virtual block device class
+ *******************************************************************************/
+
+void pvblock_init(void)
+{
+ struct driver_info info;
+ struct udevice *udev;
+ struct uclass *uc;
+ int ret;
+
+ /*
+ * At this point Xen drivers have already initialized,
+ * so we can instantiate the class driver and enumerate
+ * virtual block devices.
+ */
+ info.name = DRV_NAME;
+ ret = device_bind_by_name(gd->dm_root, false, &info, &udev);
+ if (ret < 0)
+ printf("Failed to bind " DRV_NAME ", ret: %d\n", ret);
+
+ /* Bootstrap virtual block devices class driver */
+ ret = uclass_get(UCLASS_PVBLOCK, &uc);
+ if (ret)
+ return;
+ uclass_foreach_dev_probe(UCLASS_PVBLOCK, udev);
+}
+
+static int pvblock_probe(struct udevice *udev)
+{
+ return 0;
+}
+
+U_BOOT_DRIVER(pvblock_drv) = {
+ .name = DRV_NAME,
+ .id = UCLASS_PVBLOCK,
+ .probe = pvblock_probe,
+};
+
+UCLASS_DRIVER(pvblock) = {
+ .name = DRV_NAME,
+ .id = UCLASS_PVBLOCK,
+};