From patchwork Mon Jul 20 11:02:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nastya Vicodin X-Patchwork-Id: 1332205 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=nvuUg422; 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 4B9JmN26L9z9s1x for ; Mon, 20 Jul 2020 21:05:24 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0014E81F88; Mon, 20 Jul 2020 13:03:41 +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="nvuUg422"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4E70C81F1B; Mon, 20 Jul 2020 13:03:13 +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-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) (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 5616281C40 for ; Mon, 20 Jul 2020 13:02:48 +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-x241.google.com with SMTP id e4so19760505ljn.4 for ; Mon, 20 Jul 2020 04:02:48 -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=f3PAgFmTA0juUC49zyldjpb5Ylu79FQzMxGdvUYl6hU=; b=nvuUg422d1lQ/yXvn6b4UxgWb7spZvaIBaFYivNytALqlc3lYLSsZ6bGFh+Et0PRfl f+hFa0T5VHrRx2y/qHOLsHGvkyQGJuj0sfeeNrh/Y9/nCKvqDyx26l/o9sPcjDWR1IXm nSjFbfRucMDXJmAIpjDyQDRrCC5Mb8p9o9Yqz1DIZqvOX9OGWzHgGUAELe7BXT5ejCm8 oyQgzCB+BWH3IZqrjdrL3rASqhCT235KZsOdIV4ICVDtgv0aYktSqJMLnENjkDkoDzud +ThkRCN+sR6hwJ0Ffc5RtHQyFRXYcItityM13TQ0UqTDZiPzyeKJN/h5vVQf/ClqHSD4 AMuQ== 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=f3PAgFmTA0juUC49zyldjpb5Ylu79FQzMxGdvUYl6hU=; b=dawfjXopd1BR/hbv1J7MdaUMwZVpi2zP6NC9IQm2sWCup6j/I/zVUJYwTwf1fwU/yH Dpu0CTeRbtZRME9nFvsTjAFZwt9C0VwxKpkKcrZ5sCl5fafb3r/6GVCyCMiBZvTeebD0 NJh2/oGgcb6MIpOTpot9Lp5GMNKzlUVoulle6de78nlRCZ7h25N6P8Y+EbNaYwRjAEim ASNBF6RNyPCskTRzJEI+FODJeL/AEyBNFowx69mHYXkuLcLQisG6mR3t/w2dsIa+ed5e h/l3jIgt3rneletDHjqn+uLkXOwktjcPxafNLfrcbOovQXT0idSz02LV6vQdpONY+xec iWGg== X-Gm-Message-State: AOAM531e7a34ZNdeQr4lOyw13YOglLJAZ+Ask/AwQW+jpn2noOENZmQP egGgcCpyPXwITcO4AIvYt+8MB/tNUD0IPg== X-Google-Smtp-Source: ABdhPJwHjkfjv1eap9OTTE1SkSmv/yHCFj5bO0uSn6u5QIaXerLBkDbYFFkYlJ/esgiSy+RHpvnWBw== X-Received: by 2002:a2e:89cc:: with SMTP id c12mr10689391ljk.187.1595242967336; Mon, 20 Jul 2020 04:02:47 -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 l1sm3169130ljc.65.2020.07.20.04.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2020 04:02:46 -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, vicooodin@gmail.com, Anastasiia Lukianenko , Oleksandr Andrushchenko Subject: [PATCH v2 13/18] xen: pvblock: Enumerate virtual block devices Date: Mon, 20 Jul 2020 14:02:19 +0300 Message-Id: <20200720110224.28851-14-vicooodin@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200720110224.28851-1-vicooodin@gmail.com> References: <20200720110224.28851-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 Enumerate Xen virtual block devices found in XenStore and instantiate pvblock devices. Signed-off-by: Oleksandr Andrushchenko Signed-off-by: Anastasiia Lukianenko --- 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 #include #include +#include +#include + +#include #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; }