From patchwork Thu Aug 6 09:42:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nastya Vicodin X-Patchwork-Id: 1341553 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=nVc7PjQ+; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BMkBW2Nwcz9sR4 for ; Thu, 6 Aug 2020 19:45:39 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 42C408222B; Thu, 6 Aug 2020 11:43:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nVc7PjQ+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1BA748220B; Thu, 6 Aug 2020 11:43:33 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 01046821DE for ; Thu, 6 Aug 2020 11:43:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=vicooodin@gmail.com Received: by mail-lj1-x242.google.com with SMTP id v12so20684880ljc.10 for ; Thu, 06 Aug 2020 02:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mnv70WM5QX4tVKq5k9SIj1QOuR5S/ydS3Gx9nhAzFD8=; b=nVc7PjQ+//MP3cU9vOHjglqDIVKw0pLEGpMWeSUmwVoyfI77FH6MXCCO9n6zV/KB3t NV0PcnXM2f1HB2KD+5QX2/jC57L78dbjTsjhaiI1zoBdYGubtRa56KVH4GuOXBiyPSi9 p1El+4Gx0QYmCIjNQKwaPKk53Vp8EuLE3rIh8llQKg6WdCOge03ppVecMfjvoY5kdxly 8uQYmUtEk1JwbiQ7qw43+AVSyVw4HmZa1frhihf7fXSxoJg8jE1AvsTdrzpmvQXfMWqP hvUJeKG9pKOKcT63+93y9U2x1mHIyz7hX67uGVUjWq7Cacw1vmhN18DyfPgigBNBJu36 eJ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mnv70WM5QX4tVKq5k9SIj1QOuR5S/ydS3Gx9nhAzFD8=; b=JDDaFEz6kTkHEUgE+RGFGq++dlLfrebXq2H7F/Ru6Nwnh7NSz0FvYlBUkjDcUyUOBB Wp3utEJznn6Yc+GzZzEGltfLXNyex2MNG8GjCk0zp93Ej18FMfzxb3GJGIae2p+kHH9L sllNGmxbOIjneglfrYKHL49UyqQ/gYa8dVXngPcAiyLQ5RGjqWu/Ny8SZ8Xg4LJSPbzh bR5tCtZHElIXu9zL3zoCE+61a5LqM7vfCZO9mpNK98WnIutp5A4LpJ0lRZbHQR22HQlP 2qIxMDymq429iBDdMmqc+t/3jwrU8ORtIurXL2XBqwkjQWUmmB54NxsCOHvkbNtIMLGS y6/w== X-Gm-Message-State: AOAM530v65IFT3WsYLmp0nCsVaUOhPZQo6i2JqTBxU2kcOvJqmihJea9 LH/cJ+X4Ynx0SsV1jyXvVbg9eDrwiGNUTw== X-Google-Smtp-Source: ABdhPJyzg3giPN0/ZEE0NyLkd67KNaTnw4cj+FNQ4WeyZaqTZwF3p6/xwW4BYl8zQJboc2TwNIdVoQ== X-Received: by 2002:a05:651c:503:: with SMTP id o3mr1208501ljp.312.1596707002679; Thu, 06 Aug 2020 02:43:22 -0700 (PDT) Received: from localhost.localdomain (host-176-36-213-80.la.net.ua. [176.36.213.80]) by smtp.gmail.com with ESMTPSA id j13sm2151866ljh.83.2020.08.06.02.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 02:43:22 -0700 (PDT) From: Anastasiia Lukianenko To: u-boot@lists.denx.de, sjg@chromium.org, ye.li@nxp.com, bmeng.cn@gmail.com, xypron.glpk@gmx.de Cc: julien@xen.org, sstabellini@kernel.org, peng.fan@nxp.com, roman@zededa.com, volodymyr_babchuk@epam.com, andr2000@gmail.com, vicooodin@gmail.com, Anastasiia Lukianenko , Andrii Anisov , Oleksandr Andrushchenko Subject: [RESEND PATCH v2 12/18] xen: pvblock: Add initial support for para-virtualized block driver Date: Thu, 6 Aug 2020 12:42:55 +0300 Message-Id: <20200806094301.4999-13-vicooodin@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200806094301.4999-1-vicooodin@gmail.com> References: <20200806094301.4999-1-vicooodin@gmail.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Anastasiia Lukianenko 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 Signed-off-by: Anastasiia Lukianenko Signed-off-by: Oleksandr Andrushchenko --- Changes since v1: - add comments - correct code style cmd/Kconfig | 7 ++ cmd/Makefile | 1 + cmd/pvblock.c | 30 ++++++++ common/board_r.c | 14 ++++ configs/xenguest_arm64_defconfig | 4 ++ disk/part.c | 4 ++ drivers/Kconfig | 2 + drivers/block/blk-uclass.c | 2 + drivers/xen/Kconfig | 10 +++ drivers/xen/Makefile | 2 + drivers/xen/pvblock.c | 120 +++++++++++++++++++++++++++++++ include/blk.h | 1 + include/configs/xenguest_arm64.h | 8 +++ include/dm/uclass-id.h | 1 + include/pvblock.h | 17 +++++ 15 files changed, 223 insertions(+) create mode 100644 cmd/pvblock.c create mode 100644 drivers/xen/Kconfig create mode 100644 drivers/xen/pvblock.c create mode 100644 include/pvblock.h diff --git a/cmd/Kconfig b/cmd/Kconfig index bfe6c163dc..fb6ea58d6c 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1350,6 +1350,13 @@ config CMD_USB_MASS_STORAGE help USB mass storage support +config CMD_PVBLOCK + bool "Xen para-virtualized block device" + depends on XEN + select PVBLOCK + help + Xen para-virtualized block device support + config CMD_VIRTIO bool "virtio" depends on VIRTIO diff --git a/cmd/Makefile b/cmd/Makefile index 7952138dc2..f46c4a335d 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -171,6 +171,7 @@ obj-$(CONFIG_CMD_DFU) += dfu.o obj-$(CONFIG_CMD_GPT) += gpt.o obj-$(CONFIG_CMD_ETHSW) += ethsw.o obj-$(CONFIG_CMD_AXI) += axi.o +obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o # Power obj-$(CONFIG_CMD_PMIC) += pmic.o diff --git a/cmd/pvblock.c b/cmd/pvblock.c new file mode 100644 index 0000000000..4e99b06122 --- /dev/null +++ b/cmd/pvblock.c @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2020 EPAM Systems Inc. + * + * XEN para-virtualized block device support + */ + +#include +#include +#include + +/* Current I/O Device */ +static int pvblock_curr_device; + +int do_pvblock(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + return blk_common_cmd(argc, argv, IF_TYPE_PVBLOCK, + &pvblock_curr_device); +} + +U_BOOT_CMD(pvblock, 5, 1, do_pvblock, + "Xen para-virtualized block device", + "info - show available block devices\n" + "pvblock device [dev] - show or set current device\n" + "pvblock part [dev] - print partition table of one or all devices\n" + "pvblock read addr blk# cnt\n" + "pvblock write addr blk# cnt - read/write `cnt'" + " blocks starting at block `blk#'\n" + " to/from memory address `addr'"); + diff --git a/common/board_r.c b/common/board_r.c index c8a3a8665c..6524891a9d 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -472,6 +473,16 @@ static int initr_xen(void) return 0; } #endif + +#ifdef CONFIG_PVBLOCK +static int initr_pvblock(void) +{ + puts("PVBLOCK: "); + pvblock_init(); + return 0; +} +#endif + /* * Tell if it's OK to load the environment early in boot. * @@ -768,6 +779,9 @@ static init_fnc_t init_sequence_r[] = { #endif #ifdef CONFIG_XEN initr_xen, +#endif +#ifdef CONFIG_PVBLOCK + initr_pvblock, #endif initr_env, #ifdef CONFIG_SYS_BOOTPARAMS_LEN diff --git a/configs/xenguest_arm64_defconfig b/configs/xenguest_arm64_defconfig index 45559a161b..46473c251d 100644 --- a/configs/xenguest_arm64_defconfig +++ b/configs/xenguest_arm64_defconfig @@ -14,6 +14,8 @@ CONFIG_CMD_BOOTD=n CONFIG_CMD_BOOTEFI=n CONFIG_CMD_BOOTEFI_HELLO_COMPILE=n CONFIG_CMD_ELF=n +CONFIG_CMD_EXT4=y +CONFIG_CMD_FAT=y CONFIG_CMD_GO=n CONFIG_CMD_RUN=n CONFIG_CMD_IMI=n @@ -41,6 +43,8 @@ CONFIG_CMD_LZMADEC=n CONFIG_CMD_SAVEENV=n CONFIG_CMD_UMS=n +CONFIG_CMD_PVBLOCK=y + #CONFIG_USB=n # CONFIG_ISO_PARTITION is not set diff --git a/disk/part.c b/disk/part.c index f6a31025dc..b69fd345f3 100644 --- a/disk/part.c +++ b/disk/part.c @@ -149,6 +149,7 @@ void dev_print (struct blk_desc *dev_desc) case IF_TYPE_MMC: case IF_TYPE_USB: case IF_TYPE_NVME: + case IF_TYPE_PVBLOCK: printf ("Vendor: %s Rev: %s Prod: %s\n", dev_desc->vendor, dev_desc->revision, @@ -288,6 +289,9 @@ static void print_part_header(const char *type, struct blk_desc *dev_desc) case IF_TYPE_NVME: puts ("NVMe"); break; + case IF_TYPE_PVBLOCK: + puts("PV BLOCK"); + break; case IF_TYPE_VIRTIO: puts("VirtIO"); break; diff --git a/drivers/Kconfig b/drivers/Kconfig index 7a839fa1aa..57f31f1c12 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -134,6 +134,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 b19375cbc8..6cfabbca24 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 +#include +#include +#include + +#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, +}; diff --git a/include/blk.h b/include/blk.h index abcd4bedbb..9ee10fb80e 100644 --- a/include/blk.h +++ b/include/blk.h @@ -33,6 +33,7 @@ enum if_type { IF_TYPE_HOST, IF_TYPE_NVME, IF_TYPE_EFI, + IF_TYPE_PVBLOCK, IF_TYPE_VIRTIO, IF_TYPE_COUNT, /* Number of interface types */ diff --git a/include/configs/xenguest_arm64.h b/include/configs/xenguest_arm64.h index d8958cfe75..db3059a82c 100644 --- a/include/configs/xenguest_arm64.h +++ b/include/configs/xenguest_arm64.h @@ -41,4 +41,12 @@ #define CONFIG_CMDLINE_TAG 1 #define CONFIG_INITRD_TAG 1 +#define CONFIG_CMD_RUN + +#undef CONFIG_EXTRA_ENV_SETTINGS +#define CONFIG_EXTRA_ENV_SETTINGS \ + "loadimage=ext4load pvblock 0 0x90000000 /boot/Image;\0" \ + "pvblockboot=run loadimage;" \ + "booti 0x90000000 - 0x88000000;\0" + #endif /* __XENGUEST_ARM64_H */ diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 7837d459f1..4bf7501204 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -121,6 +121,7 @@ enum uclass_id { UCLASS_W1, /* Dallas 1-Wire bus */ UCLASS_W1_EEPROM, /* one-wire EEPROMs */ UCLASS_WDT, /* Watchdog Timer driver */ + UCLASS_PVBLOCK, /* Xen virtual block device */ UCLASS_COUNT, UCLASS_INVALID = -1, diff --git a/include/pvblock.h b/include/pvblock.h new file mode 100644 index 0000000000..1023a6ab3b --- /dev/null +++ b/include/pvblock.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0+ + * + * (C) 2020 EPAM Systems Inc. + */ + +#ifndef _PVBLOCK_H +#define _PVBLOCK_H + +/** + * pvblock_init() - Initialize para-virtual block device class driver + * + * Bind PV block to UCLASS_ROOT device and probe all UCLASS_PVBLOCK + * virtual block devices. + */ +void pvblock_init(void); + +#endif /* _PVBLOCK_H */