From: Anastasiia Lukianenko <vicooodin@gmail.com>
To: u-boot@lists.denx.de
Subject: [RESEND PATCH v2 13/18] xen: pvblock: Enumerate virtual block devices
Date: Thu, 6 Aug 2020 12:42:56 +0300 [thread overview]
Message-ID: <20200806094301.4999-14-vicooodin@gmail.com> (raw)
In-Reply-To: <20200806094301.4999-1-vicooodin@gmail.com>
From: Anastasiia Lukianenko <anastasiia_lukianenko@epam.com>
Enumerate Xen virtual block devices found in XenStore and
instantiate pvblock devices.
Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Signed-off-by: Anastasiia Lukianenko <anastasiia_lukianenko@epam.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
drivers/xen/pvblock.c | 112 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 110 insertions(+), 2 deletions(-)
diff --git a/drivers/xen/pvblock.c b/drivers/xen/pvblock.c
index d2b616bb63..3ed62cac5d 100644
--- a/drivers/xen/pvblock.c
+++ b/drivers/xen/pvblock.c
@@ -6,6 +6,10 @@
#include <common.h>
#include <dm.h>
#include <dm/device-internal.h>
+#include <malloc.h>
+#include <part.h>
+
+#include <xen/xenbus.h>
#define DRV_NAME "pvblock"
#define DRV_NAME_BLK "pvblock_blk"
@@ -14,6 +18,10 @@ struct blkfront_dev {
char dummy;
};
+struct blkfront_platdata {
+ unsigned int devid;
+};
+
static int init_blkfront(unsigned int devid, struct blkfront_dev *dev)
{
return 0;
@@ -37,15 +45,40 @@ ulong pvblock_blk_write(struct udevice *udev, lbaint_t blknr, lbaint_t blkcnt,
static int pvblock_blk_bind(struct udevice *udev)
{
+ struct blk_desc *desc = dev_get_uclass_platdata(udev);
+ int devnum;
+
+ desc->if_type = IF_TYPE_PVBLOCK;
+ /*
+ * Initialize the devnum to -ENODEV. This is to make sure that
+ * blk_next_free_devnum() works as expected, since the default
+ * value 0 is a valid devnum.
+ */
+ desc->devnum = -ENODEV;
+ devnum = blk_next_free_devnum(IF_TYPE_PVBLOCK);
+ if (devnum < 0)
+ return devnum;
+ desc->devnum = devnum;
+ desc->part_type = PART_TYPE_UNKNOWN;
+ desc->bdev = udev;
+
+ strncpy(desc->vendor, "Xen", sizeof(desc->vendor));
+ strncpy(desc->revision, "1", sizeof(desc->revision));
+ strncpy(desc->product, "Virtual disk", sizeof(desc->product));
+
return 0;
}
static int pvblock_blk_probe(struct udevice *udev)
{
struct blkfront_dev *blk_dev = dev_get_priv(udev);
- int ret;
+ struct blkfront_platdata *platdata = dev_get_platdata(udev);
+ int ret, devid;
- ret = init_blkfront(0, blk_dev);
+ devid = platdata->devid;
+ free(platdata);
+
+ ret = init_blkfront(devid, blk_dev);
if (ret < 0)
return ret;
return 0;
@@ -79,6 +112,68 @@ U_BOOT_DRIVER(pvblock_blk) = {
* Para-virtual block device class
*******************************************************************************/
+typedef int (*enum_vbd_callback)(struct udevice *parent, unsigned int devid);
+
+static int on_new_vbd(struct udevice *parent, unsigned int devid)
+{
+ struct driver_info info;
+ struct udevice *udev;
+ struct blkfront_platdata *platdata;
+ int ret;
+
+ debug("New " DRV_NAME_BLK ", device ID %d\n", devid);
+
+ platdata = malloc(sizeof(struct blkfront_platdata));
+ if (!platdata) {
+ printf("Failed to allocate platform data\n");
+ return -ENOMEM;
+ }
+
+ platdata->devid = devid;
+
+ info.name = DRV_NAME_BLK;
+ info.platdata = platdata;
+
+ ret = device_bind_by_name(parent, false, &info, &udev);
+ if (ret < 0) {
+ printf("Failed to bind " DRV_NAME_BLK " to device with ID %d, ret: %d\n",
+ devid, ret);
+ free(platdata);
+ }
+ return ret;
+}
+
+static int xenbus_enumerate_vbd(struct udevice *udev, enum_vbd_callback clb)
+{
+ char **dirs, *msg;
+ int i, ret;
+
+ msg = xenbus_ls(XBT_NIL, "device/vbd", &dirs);
+ if (msg) {
+ printf("Failed to read device/vbd directory: %s\n", msg);
+ free(msg);
+ return -ENODEV;
+ }
+
+ for (i = 0; dirs[i]; i++) {
+ int devid;
+
+ sscanf(dirs[i], "%d", &devid);
+ ret = clb(udev, devid);
+ if (ret < 0)
+ goto fail;
+
+ free(dirs[i]);
+ }
+ ret = 0;
+
+fail:
+ for (; dirs[i]; i++)
+ free(dirs[i]);
+ free(dirs);
+ return ret;
+}
+
void pvblock_init(void)
{
struct driver_info info;
@@ -105,6 +200,19 @@ void pvblock_init(void)
static int pvblock_probe(struct udevice *udev)
{
+ struct uclass *uc;
+ int ret;
+
+ if (xenbus_enumerate_vbd(udev, on_new_vbd) < 0)
+ return -ENODEV;
+
+ ret = uclass_get(UCLASS_BLK, &uc);
+ if (ret)
+ return ret;
+ uclass_foreach_dev_probe(UCLASS_BLK, udev) {
+ if (_ret)
+ return _ret;
+ };
return 0;
}
--
2.17.1
next prev parent reply other threads:[~2020-08-06 9:42 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-06 9:42 [RESEND PATCH v2 00/18] Add new board: Xen guest for ARM64 Anastasiia Lukianenko
2020-08-06 9:42 ` [RESEND PATCH v2 01/18] Add MIT License Anastasiia Lukianenko
2020-08-14 19:49 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 02/18] Kconfig: Introduce CONFIG_XEN Anastasiia Lukianenko
2020-08-14 19:50 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 03/18] xen: Add essential and required interface headers Anastasiia Lukianenko
2020-08-14 19:50 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 04/18] board: Introduce xenguest_arm64 board Anastasiia Lukianenko
2020-08-14 19:50 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 05/18] xen: Port Xen hypervisor related code from mini-os Anastasiia Lukianenko
2020-08-14 19:50 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 06/18] xen: Port Xen event channel driver " Anastasiia Lukianenko
2020-08-14 19:50 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 07/18] serial: serial_xen: Add Xen PV serial driver Anastasiia Lukianenko
2020-08-14 19:50 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 08/18] linux/compat.h: Add wait_event_timeout macro Anastasiia Lukianenko
2020-08-14 19:50 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 09/18] lib: sscanf: add sscanf implementation Anastasiia Lukianenko
2020-08-14 19:50 ` Tom Rini
2020-08-16 8:23 ` Andy Shevchenko
[not found] ` <999cf014-ac1b-51b6-0522-f75e5ac3a3ed@epam.com>
2020-08-17 12:12 ` Artem Mygaiev
2020-08-17 14:19 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 10/18] xen: Port Xen bus driver from mini-os Anastasiia Lukianenko
2020-08-14 19:50 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 11/18] xen: Port Xen grant table " Anastasiia Lukianenko
2020-08-14 19:50 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 12/18] xen: pvblock: Add initial support for para-virtualized block driver Anastasiia Lukianenko
2020-08-14 19:50 ` Tom Rini
2020-08-06 9:42 ` Anastasiia Lukianenko [this message]
2020-08-14 19:51 ` [RESEND PATCH v2 13/18] xen: pvblock: Enumerate virtual block devices Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 14/18] xen: pvblock: Read XenStore configuration and initialize Anastasiia Lukianenko
2020-08-14 19:51 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 15/18] xen: pvblock: Implement front-back protocol and do IO Anastasiia Lukianenko
2020-08-14 19:51 ` Tom Rini
2020-08-06 9:42 ` [RESEND PATCH v2 16/18] xen: pvblock: Print found devices indices Anastasiia Lukianenko
2020-08-14 19:51 ` Tom Rini
2020-08-06 9:43 ` [RESEND PATCH v2 17/18] board: xen: De-initialize before jumping to Linux Anastasiia Lukianenko
2020-08-14 19:51 ` Tom Rini
2020-08-06 9:43 ` [RESEND PATCH v2 18/18] doc: xen: Add Xen guest ARM64 board documentation Anastasiia Lukianenko
2020-08-14 19:51 ` Tom Rini
2020-08-13 7:57 ` [RESEND PATCH v2 00/18] Add new board: Xen guest for ARM64 Oleksandr Andrushchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200806094301.4999-14-vicooodin@gmail.com \
--to=vicooodin@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox