From c6a49d88e2f45ecdd969c7dfebdccc44ffcbf5fc Mon Sep 17 00:00:00 2001 From: Gavin Shan Date: Fri, 10 Jun 2016 15:03:36 +1000 Subject: 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 Reviewed-by: Andrew Donnellan Signed-off-by: Stewart Smith --- core/fdt.c | 40 +++++++++++++++++++++++++++++++ doc/opal-api/opal-get-device-tree-118.txt | 24 +++++++++++++++++++ include/opal-api.h | 3 ++- 3 files changed, 66 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 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 */ -- cgit v1.1