Commit b83ba0b9 authored by Thomas Bogendoerfer's avatar Thomas Bogendoerfer
Browse files

MIPS: of: Introduce helper function to get DTB



Selection of the DTB to be used was burried in more or less readable
code in head.S. Move this code into a inline helper function and
use it.

Signed-off-by: default avatarThomas Bogendoerfer <tsbogend@alpha.franken.de>
Acked-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
parent a056aacd
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -213,16 +213,17 @@ unsigned int get_c0_compare_int(void)

void __init plat_mem_setup(void)
{
	unsigned long fdt_start;
	void *dtb;

	set_io_port_base(KSEG1);

	/* Get the position of the FDT passed by the bootloader */
	fdt_start = fw_getenvl("fdt_start");
	if (fdt_start)
		__dt_setup_arch((void *)KSEG0ADDR(fdt_start));
	else if (fw_passed_dtb)
		__dt_setup_arch((void *)KSEG0ADDR(fw_passed_dtb));
	dtb = (void *)fw_getenvl("fdt_start");
	if (dtb == NULL)
		dtb = get_fdt();

	if (dtb)
		__dt_setup_arch((void *)KSEG0ADDR(dtb));

	ath79_reset_base = ioremap(AR71XX_RESET_BASE,
					   AR71XX_RESET_SIZE);
+3 −4
Original line number Diff line number Diff line
@@ -161,11 +161,10 @@ void __init plat_mem_setup(void)
	/* intended to somewhat resemble ARM; see Documentation/arm/booting.rst */
	if (fw_arg0 == 0 && fw_arg1 == 0xffffffff)
		dtb = phys_to_virt(fw_arg2);
	else if (fw_passed_dtb) /* UHI interface or appended dtb */
		dtb = (void *)fw_passed_dtb;
	else if (&__dtb_start != &__dtb_end)
		dtb = (void *)__dtb_start;
	else
		dtb = get_fdt();

	if (!dtb)
		panic("no dtb found");

	__dt_setup_arch(dtb);
+2 −3
Original line number Diff line number Diff line
@@ -39,14 +39,13 @@ void __init *plat_get_fdt(void)
		/* Already set up */
		return (void *)fdt;

	if (fw_passed_dtb && !fdt_check_header((void *)fw_passed_dtb)) {
	fdt = (void *)get_fdt();
	if (fdt && !fdt_check_header(fdt)) {
		/*
		 * We have been provided with the appropriate device tree for
		 * the board. Make use of it & search for any machine struct
		 * based upon the root compatible string.
		 */
		fdt = (void *)fw_passed_dtb;

		for_each_mips_machine(check_mach) {
			match = mips_machine_is_compatible(check_mach, fdt);
			if (match) {
+21 −1
Original line number Diff line number Diff line
@@ -112,7 +112,27 @@ extern char arcs_cmdline[COMMAND_LINE_SIZE];
extern unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;

#ifdef CONFIG_USE_OF
extern unsigned long fw_passed_dtb;
#include <linux/libfdt.h>
#include <linux/of_fdt.h>

extern char __appended_dtb[];

static inline void *get_fdt(void)
{
	if (IS_ENABLED(CONFIG_MIPS_RAW_APPENDED_DTB) ||
	    IS_ENABLED(CONFIG_MIPS_ELF_APPENDED_DTB))
		if (fdt_magic(&__appended_dtb) == FDT_MAGIC)
			return &__appended_dtb;

	if (fw_arg0 == -2) /* UHI interface */
		return (void *)fw_arg1;

	if (IS_ENABLED(CONFIG_BUILTIN_DTB))
		if (&__dtb_start != &__dtb_end)
			return &__dtb_start;

	return NULL;
}
#endif

/*
+0 −1
Original line number Diff line number Diff line
@@ -282,7 +282,6 @@ union octeon_cvmemctl {
extern void octeon_check_cpu_bist(void);

int octeon_prune_device_tree(void);
extern const char __appended_dtb;
extern const char __dtb_octeon_3xxx_begin;
extern const char __dtb_octeon_68xx_begin;

Loading