Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: generic: Abstract FDT fixup application

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>

authored by

Paul Burton and committed by
Ralf Baechle
e889dfca c3d62fc6

+69 -22
+11 -22
arch/mips/generic/board-sead3.c
··· 138 138 return 0; 139 139 } 140 140 141 + static const struct mips_fdt_fixup sead3_fdt_fixups[] __initconst = { 142 + { yamon_dt_append_cmdline, "append command line" }, 143 + { append_memory, "append memory" }, 144 + { remove_gic, "remove GIC when not present" }, 145 + { yamon_dt_serial_config, "append serial configuration" }, 146 + { }, 147 + }; 148 + 141 149 static __init const void *sead3_fixup_fdt(const void *fdt, 142 150 const void *match_data) 143 151 { ··· 160 152 161 153 fw_init_cmdline(); 162 154 163 - err = fdt_open_into(fdt, fdt_buf, sizeof(fdt_buf)); 155 + err = apply_mips_fdt_fixups(fdt_buf, sizeof(fdt_buf), 156 + fdt, sead3_fdt_fixups); 164 157 if (err) 165 - panic("Unable to open FDT: %d", err); 166 - 167 - err = yamon_dt_append_cmdline(fdt_buf); 168 - if (err) 169 - panic("Unable to patch FDT: %d", err); 170 - 171 - err = append_memory(fdt_buf); 172 - if (err) 173 - panic("Unable to patch FDT: %d", err); 174 - 175 - err = remove_gic(fdt_buf); 176 - if (err) 177 - panic("Unable to patch FDT: %d", err); 178 - 179 - err = yamon_dt_serial_config(fdt_buf); 180 - if (err) 181 - panic("Unable to patch FDT: %d", err); 182 - 183 - err = fdt_pack(fdt_buf); 184 - if (err) 185 - panic("Unable to pack FDT: %d\n", err); 158 + panic("Unable to fixup FDT: %d", err); 186 159 187 160 return fdt_buf; 188 161 }
+27
arch/mips/generic/init.c
··· 122 122 err = register_up_smp_ops(); 123 123 } 124 124 125 + int __init apply_mips_fdt_fixups(void *fdt_out, size_t fdt_out_size, 126 + const void *fdt_in, 127 + const struct mips_fdt_fixup *fixups) 128 + { 129 + int err; 130 + 131 + err = fdt_open_into(fdt_in, fdt_out, fdt_out_size); 132 + if (err) { 133 + pr_err("Failed to open FDT\n"); 134 + return err; 135 + } 136 + 137 + for (; fixups->apply; fixups++) { 138 + err = fixups->apply(fdt_out); 139 + if (err) { 140 + pr_err("Failed to apply FDT fixup \"%s\"\n", 141 + fixups->description); 142 + return err; 143 + } 144 + } 145 + 146 + err = fdt_pack(fdt_out); 147 + if (err) 148 + pr_err("Failed to pack FDT\n"); 149 + return err; 150 + } 151 + 125 152 void __init plat_time_init(void) 126 153 { 127 154 struct device_node *np;
+31
arch/mips/include/asm/machine.h
··· 60 60 return NULL; 61 61 } 62 62 63 + /** 64 + * struct mips_fdt_fixup - Describe a fixup to apply to an FDT 65 + * @apply: applies the fixup to @fdt, returns zero on success else -errno 66 + * @description: a short description of the fixup 67 + * 68 + * Describes a fixup applied to an FDT blob by the @apply function. The 69 + * @description field provides a short description of the fixup intended for 70 + * use in error messages if the @apply function returns non-zero. 71 + */ 72 + struct mips_fdt_fixup { 73 + int (*apply)(void *fdt); 74 + const char *description; 75 + }; 76 + 77 + /** 78 + * apply_mips_fdt_fixups() - apply fixups to an FDT blob 79 + * @fdt_out: buffer in which to place the fixed-up FDT 80 + * @fdt_out_size: the size of the @fdt_out buffer 81 + * @fdt_in: the FDT blob 82 + * @fixups: pointer to an array of fixups to be applied 83 + * 84 + * Loop through the array of fixups pointed to by @fixups, calling the apply 85 + * function on each until either one returns an error or we reach the end of 86 + * the list as indicated by an entry with a NULL apply field. 87 + * 88 + * Return: zero on success, else -errno 89 + */ 90 + extern int __init apply_mips_fdt_fixups(void *fdt_out, size_t fdt_out_size, 91 + const void *fdt_in, 92 + const struct mips_fdt_fixup *fixups); 93 + 63 94 #endif /* __MIPS_ASM_MACHINE_H__ */