Message ID | 1463725945-12916-8-git-send-email-gwshan@linux.vnet.ibm.com |
---|---|
State | Changes Requested |
Headers | show |
On 20/05/16 16:32, Gavin Shan wrote: > 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> I don't see anything obviously wrong here - as far as I can tell it covers all the error paths. One minor comment below. Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> > 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. "notify the kernel of a change in hardware" Perhaps: "The typical use is for the kernel to update its device tree following a change in hardware (e.g. PCI hotplug)."
Gavin Shan <gwshan@linux.vnet.ibm.com> writes: > 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> > --- > 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 I'm good to take patch 1-7 in the next iteration with Andrew's revision.
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 */
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> --- 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