]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
MIPS: generic: Abstract FDT fixup application
authorPaul Burton <paul.burton@imgtec.com>
Fri, 2 Jun 2017 19:29:54 +0000 (12:29 -0700)
committerRalf Baechle <ralf@linux-mips.org>
Wed, 28 Jun 2017 10:22:41 +0000 (12:22 +0200)
Introduce an apply_mips_fdt_fixups() function which can apply fixups to
an FDT based upon an array of fixup descriptions. This abstracts that
functionality such that legacy board code can apply FDT fixups without
requiring lots of duplication.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/16184/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
arch/mips/generic/board-sead3.c
arch/mips/generic/init.c
arch/mips/include/asm/machine.h

index 97186a3a5d2196af4b46605fe2a3376bf25b6ea9..39e11bd249cf87fed061c06a19749a6ce92ba983 100644 (file)
@@ -138,6 +138,14 @@ static __init int remove_gic(void *fdt)
        return 0;
 }
 
+static const struct mips_fdt_fixup sead3_fdt_fixups[] __initconst = {
+       { yamon_dt_append_cmdline, "append command line" },
+       { append_memory, "append memory" },
+       { remove_gic, "remove GIC when not present" },
+       { yamon_dt_serial_config, "append serial configuration" },
+       { },
+};
+
 static __init const void *sead3_fixup_fdt(const void *fdt,
                                          const void *match_data)
 {
@@ -152,29 +160,10 @@ static __init const void *sead3_fixup_fdt(const void *fdt,
 
        fw_init_cmdline();
 
-       err = fdt_open_into(fdt, fdt_buf, sizeof(fdt_buf));
-       if (err)
-               panic("Unable to open FDT: %d", err);
-
-       err = yamon_dt_append_cmdline(fdt_buf);
-       if (err)
-               panic("Unable to patch FDT: %d", err);
-
-       err = append_memory(fdt_buf);
-       if (err)
-               panic("Unable to patch FDT: %d", err);
-
-       err = remove_gic(fdt_buf);
-       if (err)
-               panic("Unable to patch FDT: %d", err);
-
-       err = yamon_dt_serial_config(fdt_buf);
-       if (err)
-               panic("Unable to patch FDT: %d", err);
-
-       err = fdt_pack(fdt_buf);
+       err = apply_mips_fdt_fixups(fdt_buf, sizeof(fdt_buf),
+                                   fdt, sead3_fdt_fixups);
        if (err)
-               panic("Unable to pack FDT: %d\n", err);
+               panic("Unable to fixup FDT: %d", err);
 
        return fdt_buf;
 }
index 4af619215410a09946ef82c7c2cb37755423ba59..4a9a1edbfb2981bd6f1c178ee371909a8551094a 100644 (file)
@@ -122,6 +122,33 @@ void __init device_tree_init(void)
                err = register_up_smp_ops();
 }
 
+int __init apply_mips_fdt_fixups(void *fdt_out, size_t fdt_out_size,
+                                const void *fdt_in,
+                                const struct mips_fdt_fixup *fixups)
+{
+       int err;
+
+       err = fdt_open_into(fdt_in, fdt_out, fdt_out_size);
+       if (err) {
+               pr_err("Failed to open FDT\n");
+               return err;
+       }
+
+       for (; fixups->apply; fixups++) {
+               err = fixups->apply(fdt_out);
+               if (err) {
+                       pr_err("Failed to apply FDT fixup \"%s\"\n",
+                              fixups->description);
+                       return err;
+               }
+       }
+
+       err = fdt_pack(fdt_out);
+       if (err)
+               pr_err("Failed to pack FDT\n");
+       return err;
+}
+
 void __init plat_time_init(void)
 {
        struct device_node *np;
index 6b444cd9526fe362dcdeed2287c67c9e227f0d0a..ecb6c73354841741a7e9f5977ece44178065eaf5 100644 (file)
@@ -60,4 +60,35 @@ mips_machine_is_compatible(const struct mips_machine *mach, const void *fdt)
        return NULL;
 }
 
+/**
+ * struct mips_fdt_fixup - Describe a fixup to apply to an FDT
+ * @apply: applies the fixup to @fdt, returns zero on success else -errno
+ * @description: a short description of the fixup
+ *
+ * Describes a fixup applied to an FDT blob by the @apply function. The
+ * @description field provides a short description of the fixup intended for
+ * use in error messages if the @apply function returns non-zero.
+ */
+struct mips_fdt_fixup {
+       int (*apply)(void *fdt);
+       const char *description;
+};
+
+/**
+ * apply_mips_fdt_fixups() - apply fixups to an FDT blob
+ * @fdt_out: buffer in which to place the fixed-up FDT
+ * @fdt_out_size: the size of the @fdt_out buffer
+ * @fdt_in: the FDT blob
+ * @fixups: pointer to an array of fixups to be applied
+ *
+ * Loop through the array of fixups pointed to by @fixups, calling the apply
+ * function on each until either one returns an error or we reach the end of
+ * the list as indicated by an entry with a NULL apply field.
+ *
+ * Return: zero on success, else -errno
+ */
+extern int __init apply_mips_fdt_fixups(void *fdt_out, size_t fdt_out_size,
+                                       const void *fdt_in,
+                                       const struct mips_fdt_fixup *fixups);
+
 #endif /* __MIPS_ASM_MACHINE_H__ */