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

[XEN][RFC PATCH v3 13/14] tools/libs/light: Implement new libxl functions for device tree overlay ops


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vikram Garhwal <fnu.vikram@xxxxxxxxxx>
  • Date: Tue, 8 Mar 2022 11:47:03 -0800
  • 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=n0mw2y4BYfrLOmQKhWhdHmTRvK5Ny8UEy4PO2h9XNts=; b=E7YLZo25We6jEghN5JYnGXlhdi+DVL9Qz3y2ttEPrDINduLLQ54wenb9CEQfB8TtTNpuE31rMW3HuaVVec+lGSNIHOa0GUxWDjepeeeDaBBkwJh9TYnolnAkAyP5x4fsHgVCxLMbw2q77k4SnVNxTHtwk+vtR9SiiTN1Uyd1+jTXuPJGLem5U9Jv1UFyCu+SNVRdg29O4wOAr/AfO71HXxeTPEoJJnDdyrPenL3Eoql2OcqYBPofvcZ3hb+cmfaWq0uHfrrWfieSsLFa8OycB7n0Id8GSTZ0LLlgh2CnS9zeVT/Kf4v7jx9KYzpp9JBfdEMh+68ztzbXigA95y1qog==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PJ/9LP3IjTq1HpjojWR4DRKOH/RiiupFn8vgqXYhr69OIC+KKWf10dcdFVs0ClEVzuQcsu/kutMOurD0mYh95anFF9kVn4Ypo/e+BQ9B9cL+UXox7z/pJ8B83UbV47mjbyEOEhOJ+mqZOBHDThpmdReFejheTBvNBRweUyZvuKWhMCWgFUQmYiILAy5cwM/jDJDvjeLeQWKp9mX7SNAxk/YHVNCiFfVnWLjnK/IJ07xxjCe183vEFSFGq6zTZOMzzrLJRICJjCi+DMTAFveGe2jjx5Z87zpkT2b0F3FkbgtVUmlYUgmRbbjMtacT+iy1Tkb1eqpTEqEmlNPws0UGPA==
  • Cc: <sstabellini@xxxxxxxxxx>, <julien@xxxxxxx>, <bertrand.marquis@xxxxxxx>, <volodymyr_babchuk@xxxxxxxx>, Vikram Garhwal <fnu.vikram@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Tue, 08 Mar 2022 19:47:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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

diff --git a/tools/include/libxl.h b/tools/include/libxl.h
index 51a9b6cfac..b31e17c2ce 100644
--- a/tools/include/libxl.h
+++ b/tools/include/libxl.h
@@ -2419,6 +2419,9 @@ 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);
 
+int libxl_dt_overlay(libxl_ctx *ctx, void *overlay,
+                     int overlay_size, uint8_t overlay_op);
+
 /*
  * 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 453bea0067..405115c13c 100644
--- a/tools/libs/light/Makefile
+++ b/tools/libs/light/Makefile
@@ -116,6 +116,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_overlay.o
 
 ifeq ($(CONFIG_LIBNL),y)
 CFLAGS_LIBXL += $(LIBNL3_CFLAGS)
diff --git a/tools/libs/light/libxl_overlay.c b/tools/libs/light/libxl_overlay.c
new file mode 100644
index 0000000000..e370e8cac8
--- /dev/null
+++ b/tools/libs/light/libxl_overlay.c
@@ -0,0 +1,67 @@
+/*
+ * 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_overlay_fdt(libxl__gc *gc, void *fdt, size_t size)
+{
+    int r;
+
+    if (fdt_magic(fdt) != FDT_MAGIC) {
+        LOG(ERROR, "Overlay FDT is not a valid Flat Device Tree");
+        return ERROR_FAIL;
+    }
+
+    r = fdt_check_header(fdt);
+    if (r) {
+        LOG(ERROR, "Failed to check the overlay FDT (%d)", r);
+        return ERROR_FAIL;
+    }
+
+    if (fdt_totalsize(fdt) > size) {
+        LOG(ERROR, "Overlay FDT totalsize is too big");
+        return ERROR_FAIL;
+    }
+
+    return 0;
+}
+
+int libxl_dt_overlay(libxl_ctx *ctx, void *overlay_dt, int overlay_dt_size,
+                     uint8_t overlay_op)
+{
+    int rc = 0;
+    GC_INIT(ctx);
+
+    if (check_overlay_fdt(gc, overlay_dt, overlay_dt_size)) {
+        LOG(ERROR, "Overlay DTB check failed\n");
+        GC_FREE;
+        return ERROR_FAIL;
+    } else
+        LOG(DEBUG, "Overlay DTB check passed\n");
+
+    /* We don't need to do  xc_interface_open here. */
+    rc = xc_dt_overlay(ctx->xch, overlay_dt, overlay_dt_size, overlay_op);
+
+    if (rc)
+        LOG(ERROR, "%s: Adding/Removing overlay dtb failed.\n", __func__);
+
+    GC_FREE;
+    return rc;
+}
+
-- 
2.17.1




 


Rackspace

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