1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2f2ffa5abSDezhong Diao /* 3f2ffa5abSDezhong Diao * MIPS support for CONFIG_OF device tree support 4f2ffa5abSDezhong Diao * 5f2ffa5abSDezhong Diao * Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com> 6f2ffa5abSDezhong Diao */ 7f2ffa5abSDezhong Diao 8f2ffa5abSDezhong Diao #include <linux/init.h> 973bc256dSPaul Gortmaker #include <linux/export.h> 10f2ffa5abSDezhong Diao #include <linux/errno.h> 11f2ffa5abSDezhong Diao #include <linux/types.h> 1257c8a661SMike Rapoport #include <linux/memblock.h> 13f2ffa5abSDezhong Diao #include <linux/debugfs.h> 14f2ffa5abSDezhong Diao #include <linux/of.h> 15f2ffa5abSDezhong Diao #include <linux/of_fdt.h> 1684988c06SKevin Cernekee #include <linux/of_platform.h> 17f2ffa5abSDezhong Diao 1801306aeaSRob Herring #include <asm/bootinfo.h> 19f2ffa5abSDezhong Diao #include <asm/page.h> 20f2ffa5abSDezhong Diao #include <asm/prom.h> 21f2ffa5abSDezhong Diao 229169a5d0SJohn Crispin static char mips_machine_name[64] = "Unknown"; 239169a5d0SJohn Crispin 249169a5d0SJohn Crispin __init void mips_set_machine_name(const char *name) 259169a5d0SJohn Crispin { 269169a5d0SJohn Crispin if (name == NULL) 279169a5d0SJohn Crispin return; 289169a5d0SJohn Crispin 2941c8366bSChen Gang strlcpy(mips_machine_name, name, sizeof(mips_machine_name)); 309169a5d0SJohn Crispin pr_info("MIPS: machine is %s\n", mips_get_machine_name()); 319169a5d0SJohn Crispin } 329169a5d0SJohn Crispin 339169a5d0SJohn Crispin char *mips_get_machine_name(void) 349169a5d0SJohn Crispin { 359169a5d0SJohn Crispin return mips_machine_name; 369169a5d0SJohn Crispin } 379169a5d0SJohn Crispin 38d3557d96SJonas Gorski #ifdef CONFIG_USE_OF 39f2ffa5abSDezhong Diao void __init early_init_dt_add_memory_arch(u64 base, u64 size) 40f2ffa5abSDezhong Diao { 4193fa5b28SSerge Semin if (base >= PHYS_ADDR_MAX) { 4293fa5b28SSerge Semin pr_warn("Trying to add an invalid memory region, skipped\n"); 4393fa5b28SSerge Semin return; 4493fa5b28SSerge Semin } 4593fa5b28SSerge Semin 4693fa5b28SSerge Semin /* Truncate the passed memory region instead of type casting */ 4793fa5b28SSerge Semin if (base + size - 1 >= PHYS_ADDR_MAX || base + size < base) { 4893fa5b28SSerge Semin pr_warn("Truncate memory region %llx @ %llx to size %llx\n", 4993fa5b28SSerge Semin size, base, PHYS_ADDR_MAX - base); 5093fa5b28SSerge Semin size = PHYS_ADDR_MAX - base; 5193fa5b28SSerge Semin } 5293fa5b28SSerge Semin 5393fa5b28SSerge Semin add_memory_region(base, size, BOOT_MEM_RAM); 54f2ffa5abSDezhong Diao } 55f2ffa5abSDezhong Diao 5673346081SMarcin Nowakowski int __init early_init_dt_reserve_memory_arch(phys_addr_t base, 5773346081SMarcin Nowakowski phys_addr_t size, bool nomap) 5873346081SMarcin Nowakowski { 599b9a59dbSSerge Semin add_memory_region(base, size, 609b9a59dbSSerge Semin nomap ? BOOT_MEM_NOMAP : BOOT_MEM_RESERVED); 619b9a59dbSSerge Semin 6273346081SMarcin Nowakowski return 0; 6373346081SMarcin Nowakowski } 6473346081SMarcin Nowakowski 650cdde839SRob Herring void __init __dt_setup_arch(void *bph) 66f2ffa5abSDezhong Diao { 67f75813c0SRob Herring if (!early_init_dt_scan(bph)) 68f75813c0SRob Herring return; 699169a5d0SJohn Crispin 7097e7f455SRob Herring mips_set_machine_name(of_flat_dt_get_machine_name()); 71f2ffa5abSDezhong Diao } 7284988c06SKevin Cernekee 7384988c06SKevin Cernekee int __init __dt_register_buses(const char *bus0, const char *bus1) 7484988c06SKevin Cernekee { 7584988c06SKevin Cernekee static struct of_device_id of_ids[3]; 7684988c06SKevin Cernekee 7784988c06SKevin Cernekee if (!of_have_populated_dt()) 7884988c06SKevin Cernekee panic("device tree not present"); 7984988c06SKevin Cernekee 8084988c06SKevin Cernekee strlcpy(of_ids[0].compatible, bus0, sizeof(of_ids[0].compatible)); 819127dc47SKevin Cernekee if (bus1) { 829127dc47SKevin Cernekee strlcpy(of_ids[1].compatible, bus1, 839127dc47SKevin Cernekee sizeof(of_ids[1].compatible)); 849127dc47SKevin Cernekee } 8584988c06SKevin Cernekee 8684988c06SKevin Cernekee if (of_platform_populate(NULL, of_ids, NULL, NULL)) 8784988c06SKevin Cernekee panic("failed to populate DT"); 8884988c06SKevin Cernekee 8984988c06SKevin Cernekee return 0; 9084988c06SKevin Cernekee } 9184988c06SKevin Cernekee 929169a5d0SJohn Crispin #endif 93