mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-14 06:24:53 +08:00
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>
This commit is contained in:
parent
c3d62fc6a0
commit
e889dfca12
@ -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));
|
||||
err = apply_mips_fdt_fixups(fdt_buf, sizeof(fdt_buf),
|
||||
fdt, sead3_fdt_fixups);
|
||||
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);
|
||||
if (err)
|
||||
panic("Unable to pack FDT: %d\n", err);
|
||||
panic("Unable to fixup FDT: %d", err);
|
||||
|
||||
return fdt_buf;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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__ */
|
||||
|
Loading…
Reference in New Issue
Block a user