aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGavin Shan <gwshan@linux.vnet.ibm.com>2016-06-10 15:03:36 +1000
committerStewart Smith <stewart@linux.vnet.ibm.com>2016-06-14 16:00:16 +1000
commitc6a49d88e2f45ecdd969c7dfebdccc44ffcbf5fc (patch)
tree45aa35bee3ffcec7eed2161cec050f86723bfbf6
parent229c79d4903ae6d292354eebef56039f7d8219d6 (diff)
downloadskiboot-c6a49d88e2f45ecdd969c7dfebdccc44ffcbf5fc.zip
skiboot-c6a49d88e2f45ecdd969c7dfebdccc44ffcbf5fc.tar.gz
skiboot-c6a49d88e2f45ecdd969c7dfebdccc44ffcbf5fc.tar.bz2
core/fdt: Introduce opal_get_device_tree()
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@linux.vnet.ibm.com> Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r--core/fdt.c40
-rw-r--r--doc/opal-api/opal-get-device-tree-118.txt24
-rw-r--r--include/opal-api.h3
3 files changed, 66 insertions, 1 deletions
diff --git a/core/fdt.c b/core/fdt.c
index 71149fe..a22a840 100644
--- a/core/fdt.c
+++ b/core/fdt.c
@@ -216,3 +216,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..235a321
--- /dev/null
+++ b/doc/opal-api/opal-get-device-tree-118.txt
@@ -0,0 +1,24 @@
+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 for the kernel to update its device tree following a change
+in hardware (e.g. PCI hotplug).
+
+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 f88e97f..2f91715 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 */