[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XEN][RFC PATCH 12/13] tools/libs/light: Implement new libxl functions for fpga-add and fpga-del


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <fnu.vikram@xxxxxxxxxx>
  • Date: Wed, 1 Sep 2021 23:06:02 -0700
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U7bgcXdJTXoKYKNKTamQfYEjcYOoItL0nadg/TeJWjc=; b=mCyKJMgU9KJR2RtMojV/Nq0IeDvxGu8cciiDV6vgXxXvjrWj2YRRx7I2AzY38N1UdzdvOgh4xi6nk9LpDA+IMz7IU+v6u2krT0D5+nlafEs9Mlc/thIRB9/f+HueuSPg/MzfghNoCoH0BQXn+HvbqziYrlX7dBED9WI6WNok43sUhExApe4rGUy5ruW0DJcToXlawTIBdQDNJOZ6pNpuml+IciSWp+0ITRqq2I6lQBShh0erdZVReobp6e9oRS8JH0PCdrz9jxTXADdWK/DuvCe9dt2eO2pZm51SeD2FwORtIOlMoj07k1gPrdl9ZkfVklibdDbwKiS/FzLqT9VnPQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LnC/zNap3NmjyBziOpMvDWQXaPdOpD89oEQX+ubKVltND/+dxXMhbCEef2RIk5fspdbgiS9gDPtZQq3zCITQVgOVF1uZiVBRGPBF7wpnaJTpPeHrFM6OkggsLyVJXDrhtYW2hrXmePDB4S66IzUgNe1UyNA2WdXvOQQLI4APdUegOtGSTURqS7M+l4rabkrgmWs2KasRCUHP8uTwnNkhmUMw8levOdkR+5/ef3tXxyRGteEuIiiPxpHccPEQ0mrrxSu5Lf1S0P9rmY1nIWJnpDRWxnOupSWTCQf0yuuFfW6LcczPQwRCjIjtYlwpFaunZxeeisESEJ6n96k94KLBag==
  • Cc: <sstabellini@xxxxxxxxxx>, <julien@xxxxxxx>, Vikram Garhwal <fnu.vikram@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Thu, 02 Sep 2021 06:51:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Signed-off-by: Vikram Garhwal <fnu.vikram@xxxxxxxxxx>
---
 tools/include/libxl.h         |  5 +++
 tools/libs/light/Makefile     |  1 +
 tools/libs/light/libxl_fpga.c | 73 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
 create mode 100644 tools/libs/light/libxl_fpga.c

diff --git a/tools/include/libxl.h b/tools/include/libxl.h
index b9ba16d..896cbcf 100644
--- a/tools/include/libxl.h
+++ b/tools/include/libxl.h
@@ -2386,6 +2386,11 @@ libxl_device_pci *libxl_device_pci_list(libxl_ctx *ctx, 
uint32_t domid,
                                         int *num);
 void libxl_device_pci_list_free(libxl_device_pci* list, int num);
 
+/* FPGA device add. */
+int libxl_add_fpga_node(libxl_ctx *ctx, void *pfdt, int pfdt_size);
+/* FPGA device remove. */
+int libxl_del_fpga_node(libxl_ctx *ctx, char *full_dt_node_path);
+
 /*
  * Turns the current process into a backend device service daemon
  * for a driver domain.
diff --git a/tools/libs/light/Makefile b/tools/libs/light/Makefile
index 7d8c51d..b17d4a6 100644
--- a/tools/libs/light/Makefile
+++ b/tools/libs/light/Makefile
@@ -115,6 +115,7 @@ SRCS-y += libxl_genid.c
 SRCS-y += _libxl_types.c
 SRCS-y += libxl_flask.c
 SRCS-y += _libxl_types_internal.c
+SRCS-y += libxl_fpga.o
 
 ifeq ($(CONFIG_LIBNL),y)
 CFLAGS_LIBXL += $(LIBNL3_CFLAGS)
diff --git a/tools/libs/light/libxl_fpga.c b/tools/libs/light/libxl_fpga.c
new file mode 100644
index 0000000..a33d00f
--- /dev/null
+++ b/tools/libs/light/libxl_fpga.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2021 Xilinx Inc.
+ * Author Vikram Garhwal <fnu.vikram@xxxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include "libxl_osdeps.h" /* must come before any other headers */
+#include "libxl_internal.h"
+#include <libfdt.h>
+#include <xenguest.h>
+#include <xenctrl.h>
+
+static int check_partial_fdt(libxl__gc *gc, void *fdt, size_t size)
+{
+    int r;
+
+    if (fdt_magic(fdt) != FDT_MAGIC) {
+        LOG(ERROR, "Partial FDT is not a valid Flat Device Tree");
+        return ERROR_FAIL;
+    }
+
+    r = fdt_check_header(fdt);
+    if (r) {
+        LOG(ERROR, "Failed to check the partial FDT (%d)", r);
+        return ERROR_FAIL;
+    }
+
+    if (fdt_totalsize(fdt) > size) {
+        LOG(ERROR, "Partial FDT totalsize is too big");
+        return ERROR_FAIL;
+    }
+
+    return 0;
+}
+
+int libxl_add_fpga_node(libxl_ctx *ctx, void *pfdt, int pfdt_size)
+{
+    int rc = 0;
+    GC_INIT(ctx);
+
+    if (check_partial_fdt(gc, pfdt, pfdt_size)) {
+        LOG(ERROR, "Partial DTB check failed\n");
+        return ERROR_FAIL;
+    } else
+        LOG(DEBUG, "Partial DTB check passed\n");
+
+    /* We don't need to do  xc_interface_open here. */
+    rc = xc_domain_add_fpga(ctx->xch, pfdt, pfdt_size);
+
+    if (rc)
+        LOG(ERROR, "%s: Adding partial dtb failed.\n", __func__);
+
+    return rc;
+}
+
+int libxl_del_fpga_node(libxl_ctx *ctx, char *device_path)
+{
+    int rc = 0;
+
+    /* We don't need to do  xc_interface_open here. */
+    rc = xc_domain_del_fpga(ctx->xch, device_path);
+
+    return rc;
+}
-- 
2.7.4




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.