Skip to content

Commit 0857bef

Browse files
sourabhjainsmpe
authored andcommitted
powerpc/kexec: make the update_cpus_node() function public
Move the update_cpus_node() from kexec/{file_load_64.c => core_64.c} to allow other kexec components to use it. Later in the series, this function is used for in-kernel updates to the kdump image during CPU/memory hotplug or online/offline events for both kexec_load and kexec_file_load syscalls. No functional changes are intended. Signed-off-by: Sourabh Jain <[email protected]> Acked-by: Hari Bathini <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected]
1 parent f5f0da5 commit 0857bef

File tree

3 files changed

+95
-87
lines changed

3 files changed

+95
-87
lines changed

arch/powerpc/include/asm/kexec.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ static inline void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
185185

186186
#endif /* CONFIG_CRASH_DUMP */
187187

188+
#if defined(CONFIG_KEXEC_FILE) || defined(CONFIG_CRASH_DUMP)
189+
int update_cpus_node(void *fdt);
190+
#endif
191+
188192
#ifdef CONFIG_PPC_BOOK3S_64
189193
#include <asm/book3s/64/kexec.h>
190194
#endif

arch/powerpc/kexec/core_64.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/cpu.h>
1818
#include <linux/hardirq.h>
1919
#include <linux/of.h>
20+
#include <linux/libfdt.h>
2021

2122
#include <asm/page.h>
2223
#include <asm/current.h>
@@ -30,6 +31,7 @@
3031
#include <asm/hw_breakpoint.h>
3132
#include <asm/svm.h>
3233
#include <asm/ultravisor.h>
34+
#include <asm/crashdump-ppc64.h>
3335

3436
int machine_kexec_prepare(struct kimage *image)
3537
{
@@ -419,3 +421,92 @@ static int __init export_htab_values(void)
419421
}
420422
late_initcall(export_htab_values);
421423
#endif /* CONFIG_PPC_64S_HASH_MMU */
424+
425+
#if defined(CONFIG_KEXEC_FILE) || defined(CONFIG_CRASH_DUMP)
426+
/**
427+
* add_node_props - Reads node properties from device node structure and add
428+
* them to fdt.
429+
* @fdt: Flattened device tree of the kernel
430+
* @node_offset: offset of the node to add a property at
431+
* @dn: device node pointer
432+
*
433+
* Returns 0 on success, negative errno on error.
434+
*/
435+
static int add_node_props(void *fdt, int node_offset, const struct device_node *dn)
436+
{
437+
int ret = 0;
438+
struct property *pp;
439+
440+
if (!dn)
441+
return -EINVAL;
442+
443+
for_each_property_of_node(dn, pp) {
444+
ret = fdt_setprop(fdt, node_offset, pp->name, pp->value, pp->length);
445+
if (ret < 0) {
446+
pr_err("Unable to add %s property: %s\n", pp->name, fdt_strerror(ret));
447+
return ret;
448+
}
449+
}
450+
return ret;
451+
}
452+
453+
/**
454+
* update_cpus_node - Update cpus node of flattened device tree using of_root
455+
* device node.
456+
* @fdt: Flattened device tree of the kernel.
457+
*
458+
* Returns 0 on success, negative errno on error.
459+
*/
460+
int update_cpus_node(void *fdt)
461+
{
462+
struct device_node *cpus_node, *dn;
463+
int cpus_offset, cpus_subnode_offset, ret = 0;
464+
465+
cpus_offset = fdt_path_offset(fdt, "/cpus");
466+
if (cpus_offset < 0 && cpus_offset != -FDT_ERR_NOTFOUND) {
467+
pr_err("Malformed device tree: error reading /cpus node: %s\n",
468+
fdt_strerror(cpus_offset));
469+
return cpus_offset;
470+
}
471+
472+
if (cpus_offset > 0) {
473+
ret = fdt_del_node(fdt, cpus_offset);
474+
if (ret < 0) {
475+
pr_err("Error deleting /cpus node: %s\n", fdt_strerror(ret));
476+
return -EINVAL;
477+
}
478+
}
479+
480+
/* Add cpus node to fdt */
481+
cpus_offset = fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "cpus");
482+
if (cpus_offset < 0) {
483+
pr_err("Error creating /cpus node: %s\n", fdt_strerror(cpus_offset));
484+
return -EINVAL;
485+
}
486+
487+
/* Add cpus node properties */
488+
cpus_node = of_find_node_by_path("/cpus");
489+
ret = add_node_props(fdt, cpus_offset, cpus_node);
490+
of_node_put(cpus_node);
491+
if (ret < 0)
492+
return ret;
493+
494+
/* Loop through all subnodes of cpus and add them to fdt */
495+
for_each_node_by_type(dn, "cpu") {
496+
cpus_subnode_offset = fdt_add_subnode(fdt, cpus_offset, dn->full_name);
497+
if (cpus_subnode_offset < 0) {
498+
pr_err("Unable to add %s subnode: %s\n", dn->full_name,
499+
fdt_strerror(cpus_subnode_offset));
500+
ret = cpus_subnode_offset;
501+
goto out;
502+
}
503+
504+
ret = add_node_props(fdt, cpus_subnode_offset, dn);
505+
if (ret < 0)
506+
goto out;
507+
}
508+
out:
509+
of_node_put(dn);
510+
return ret;
511+
}
512+
#endif /* CONFIG_KEXEC_FILE || CONFIG_CRASH_DUMP */

arch/powerpc/kexec/file_load_64.c

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -838,93 +838,6 @@ unsigned int kexec_extra_fdt_size_ppc64(struct kimage *image)
838838
return extra_size + kdump_extra_fdt_size_ppc64(image);
839839
}
840840

841-
/**
842-
* add_node_props - Reads node properties from device node structure and add
843-
* them to fdt.
844-
* @fdt: Flattened device tree of the kernel
845-
* @node_offset: offset of the node to add a property at
846-
* @dn: device node pointer
847-
*
848-
* Returns 0 on success, negative errno on error.
849-
*/
850-
static int add_node_props(void *fdt, int node_offset, const struct device_node *dn)
851-
{
852-
int ret = 0;
853-
struct property *pp;
854-
855-
if (!dn)
856-
return -EINVAL;
857-
858-
for_each_property_of_node(dn, pp) {
859-
ret = fdt_setprop(fdt, node_offset, pp->name, pp->value, pp->length);
860-
if (ret < 0) {
861-
pr_err("Unable to add %s property: %s\n", pp->name, fdt_strerror(ret));
862-
return ret;
863-
}
864-
}
865-
return ret;
866-
}
867-
868-
/**
869-
* update_cpus_node - Update cpus node of flattened device tree using of_root
870-
* device node.
871-
* @fdt: Flattened device tree of the kernel.
872-
*
873-
* Returns 0 on success, negative errno on error.
874-
*/
875-
static int update_cpus_node(void *fdt)
876-
{
877-
struct device_node *cpus_node, *dn;
878-
int cpus_offset, cpus_subnode_offset, ret = 0;
879-
880-
cpus_offset = fdt_path_offset(fdt, "/cpus");
881-
if (cpus_offset < 0 && cpus_offset != -FDT_ERR_NOTFOUND) {
882-
pr_err("Malformed device tree: error reading /cpus node: %s\n",
883-
fdt_strerror(cpus_offset));
884-
return cpus_offset;
885-
}
886-
887-
if (cpus_offset > 0) {
888-
ret = fdt_del_node(fdt, cpus_offset);
889-
if (ret < 0) {
890-
pr_err("Error deleting /cpus node: %s\n", fdt_strerror(ret));
891-
return -EINVAL;
892-
}
893-
}
894-
895-
/* Add cpus node to fdt */
896-
cpus_offset = fdt_add_subnode(fdt, fdt_path_offset(fdt, "/"), "cpus");
897-
if (cpus_offset < 0) {
898-
pr_err("Error creating /cpus node: %s\n", fdt_strerror(cpus_offset));
899-
return -EINVAL;
900-
}
901-
902-
/* Add cpus node properties */
903-
cpus_node = of_find_node_by_path("/cpus");
904-
ret = add_node_props(fdt, cpus_offset, cpus_node);
905-
of_node_put(cpus_node);
906-
if (ret < 0)
907-
return ret;
908-
909-
/* Loop through all subnodes of cpus and add them to fdt */
910-
for_each_node_by_type(dn, "cpu") {
911-
cpus_subnode_offset = fdt_add_subnode(fdt, cpus_offset, dn->full_name);
912-
if (cpus_subnode_offset < 0) {
913-
pr_err("Unable to add %s subnode: %s\n", dn->full_name,
914-
fdt_strerror(cpus_subnode_offset));
915-
ret = cpus_subnode_offset;
916-
goto out;
917-
}
918-
919-
ret = add_node_props(fdt, cpus_subnode_offset, dn);
920-
if (ret < 0)
921-
goto out;
922-
}
923-
out:
924-
of_node_put(dn);
925-
return ret;
926-
}
927-
928841
static int copy_property(void *fdt, int node_offset, const struct device_node *dn,
929842
const char *propname)
930843
{

0 commit comments

Comments
 (0)