diff options
-rw-r--r-- | arch/mips/generic/board-sead3.c | 33 | ||||
-rw-r--r-- | arch/mips/generic/init.c | 27 | ||||
-rw-r--r-- | arch/mips/include/asm/machine.h | 31 |
3 files changed, 69 insertions, 22 deletions
diff --git a/arch/mips/generic/board-sead3.c b/arch/mips/generic/board-sead3.c index 97186a3a5d21..39e11bd249cf 100644 --- a/arch/mips/generic/board-sead3.c +++ b/arch/mips/generic/board-sead3.c | |||
@@ -138,6 +138,14 @@ static __init int remove_gic(void *fdt) | |||
138 | return 0; | 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 | static __init const void *sead3_fixup_fdt(const void *fdt, | 149 | static __init const void *sead3_fixup_fdt(const void *fdt, |
142 | const void *match_data) | 150 | const void *match_data) |
143 | { | 151 | { |
@@ -152,29 +160,10 @@ static __init const void *sead3_fixup_fdt(const void *fdt, | |||
152 | 160 | ||
153 | fw_init_cmdline(); | 161 | fw_init_cmdline(); |
154 | 162 | ||
155 | err = fdt_open_into(fdt, fdt_buf, sizeof(fdt_buf)); | 163 | err = apply_mips_fdt_fixups(fdt_buf, sizeof(fdt_buf), |
156 | if (err) | 164 | fdt, sead3_fdt_fixups); |
157 | panic("Unable to open FDT: %d", err); | ||
158 | |||
159 | err = yamon_dt_append_cmdline(fdt_buf); | ||
160 | if (err) | ||
161 | panic("Unable to patch FDT: %d", err); | ||
162 | |||
163 | err = append_memory(fdt_buf); | ||
164 | if (err) | ||
165 | panic("Unable to patch FDT: %d", err); | ||
166 | |||
167 | err = remove_gic(fdt_buf); | ||
168 | if (err) | ||
169 | panic("Unable to patch FDT: %d", err); | ||
170 | |||
171 | err = yamon_dt_serial_config(fdt_buf); | ||
172 | if (err) | ||
173 | panic("Unable to patch FDT: %d", err); | ||
174 | |||
175 | err = fdt_pack(fdt_buf); | ||
176 | if (err) | 165 | if (err) |
177 | panic("Unable to pack FDT: %d\n", err); | 166 | panic("Unable to fixup FDT: %d", err); |
178 | 167 | ||
179 | return fdt_buf; | 168 | return fdt_buf; |
180 | } | 169 | } |
diff --git a/arch/mips/generic/init.c b/arch/mips/generic/init.c index 4af619215410..4a9a1edbfb29 100644 --- a/arch/mips/generic/init.c +++ b/arch/mips/generic/init.c | |||
@@ -122,6 +122,33 @@ void __init device_tree_init(void) | |||
122 | err = register_up_smp_ops(); | 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 | void __init plat_time_init(void) | 152 | void __init plat_time_init(void) |
126 | { | 153 | { |
127 | struct device_node *np; | 154 | struct device_node *np; |
diff --git a/arch/mips/include/asm/machine.h b/arch/mips/include/asm/machine.h index 6b444cd9526f..ecb6c7335484 100644 --- a/arch/mips/include/asm/machine.h +++ b/arch/mips/include/asm/machine.h | |||
@@ -60,4 +60,35 @@ mips_machine_is_compatible(const struct mips_machine *mach, const void *fdt) | |||
60 | return NULL; | 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 | #endif /* __MIPS_ASM_MACHINE_H__ */ | 94 | #endif /* __MIPS_ASM_MACHINE_H__ */ |