[Skiboot] [PATCH v11 07/23] core/fdt: Introduce opal_get_device_tree()

Gavin Shan gwshan at linux.vnet.ibm.com
Fri May 20 16:32:09 AEST 2016


This introduces OPAL API opal_get_device_tree() to get the device
sub-tree. It's going to be used in PCI hot add path.

Signed-off-by: Gavin Shan <gwshan at linux.vnet.ibm.com>
---
 core/fdt.c                                | 40 +++++++++++++++++++++++++++++++
 doc/opal-api/opal-get-device-tree-118.txt | 23 ++++++++++++++++++
 include/opal-api.h                        |  3 ++-
 3 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100644 doc/opal-api/opal-get-device-tree-118.txt

diff --git a/core/fdt.c b/core/fdt.c
index b4c23e6..b6187bf 100644
--- a/core/fdt.c
+++ b/core/fdt.c
@@ -217,3 +217,43 @@ void *create_dtb(const struct dt_node *root, bool exclusive)
 
 	return fdt;
 }
+
+static int64_t opal_get_device_tree(uint32_t phandle,
+				    uint64_t buf, uint64_t len)
+{
+	struct dt_node *root;
+	void *fdt = (void *)buf;
+	uint32_t old_last_phandle;
+	int64_t totalsize;
+	int ret;
+
+	root = dt_find_by_phandle(dt_root, phandle);
+	if (!root)
+		return OPAL_PARAMETER;
+
+	if (!fdt) {
+		fdt = create_dtb(root, true);
+		if (!fdt)
+			return OPAL_INTERNAL_ERROR;
+		totalsize = fdt_totalsize(fdt);
+		free(fdt);
+		return totalsize;
+	}
+
+	if (!len)
+		return OPAL_PARAMETER;
+
+	fdt_error = 0;
+	old_last_phandle = last_phandle;
+	ret = __create_dtb(fdt, len, root, true);
+	if (ret) {
+		last_phandle = old_last_phandle;
+		if (ret == -FDT_ERR_NOSPACE)
+			return OPAL_NO_MEM;
+
+		return OPAL_EMPTY;
+	}
+
+	return OPAL_SUCCESS;
+}
+opal_call(OPAL_GET_DEVICE_TREE, opal_get_device_tree, 3);
diff --git a/doc/opal-api/opal-get-device-tree-118.txt b/doc/opal-api/opal-get-device-tree-118.txt
new file mode 100644
index 0000000..cacbd96
--- /dev/null
+++ b/doc/opal-api/opal-get-device-tree-118.txt
@@ -0,0 +1,23 @@
+OPAL_GET_DEVICE_TREE
+--------------------
+
+Get device sub-tree
+
+Parameters:
+	uint32_t phandle: root device node phandle of the device sub-tree
+	uint64_t buf: FDT blob buffer or NULL
+	uint64_t len: length of the FDT blob buffer
+
+Calling:
+
+Retrieve device sub-tree. The root node's phandle is identified by @phandle.
+The typical use is notify kernel a change in hardware.
+
+Return Codes:
+
+FDT blob size - returned FDT blob buffer size when @buf is NULL
+OPAL_SUCCESS - FDT blob is created successfully
+OPAL_PARAMETER - invalid argument @phandle or @len
+OPAL_INTERNAL_ERROR - failure creating FDT blob when calculating its size
+OPAL_NO_MEM - not enough room in buffer for device sub-tree
+OPAL_EMPTY - failure creating FDT blob
diff --git a/include/opal-api.h b/include/opal-api.h
index 0b7b0bb..41af0e5 100644
--- a/include/opal-api.h
+++ b/include/opal-api.h
@@ -163,7 +163,8 @@
 #define OPAL_LEDS_SET_INDICATOR			115
 #define OPAL_CEC_REBOOT2			116
 #define OPAL_CONSOLE_FLUSH			117
-#define OPAL_LAST				117
+#define OPAL_GET_DEVICE_TREE			118
+#define OPAL_LAST				118
 
 /* Device tree flags */
 
-- 
2.1.0



More information about the Skiboot mailing list