18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights 38c2ecf20Sopenharmony_ci * reserved. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two 68c2ecf20Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 78c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 88c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the NetLogic 98c2ecf20Sopenharmony_ci * license below: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 128c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 138c2ecf20Sopenharmony_ci * are met: 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 168c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 178c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 188c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in 198c2ecf20Sopenharmony_ci * the documentation and/or other materials provided with the 208c2ecf20Sopenharmony_ci * distribution. 218c2ecf20Sopenharmony_ci * 228c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR 238c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 248c2ecf20Sopenharmony_ci * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 258c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE 268c2ecf20Sopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 278c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 288c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 298c2ecf20Sopenharmony_ci * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 308c2ecf20Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 318c2ecf20Sopenharmony_ci * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 328c2ecf20Sopenharmony_ci * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 338c2ecf20Sopenharmony_ci */ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include <linux/kernel.h> 368c2ecf20Sopenharmony_ci#include <linux/of_fdt.h> 378c2ecf20Sopenharmony_ci#include <linux/memblock.h> 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#include <asm/idle.h> 408c2ecf20Sopenharmony_ci#include <asm/reboot.h> 418c2ecf20Sopenharmony_ci#include <asm/time.h> 428c2ecf20Sopenharmony_ci#include <asm/bootinfo.h> 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci#include <asm/netlogic/haldefs.h> 458c2ecf20Sopenharmony_ci#include <asm/netlogic/common.h> 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#include <asm/netlogic/xlp-hal/iomap.h> 488c2ecf20Sopenharmony_ci#include <asm/netlogic/xlp-hal/xlp.h> 498c2ecf20Sopenharmony_ci#include <asm/netlogic/xlp-hal/sys.h> 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciuint64_t nlm_io_base; 528c2ecf20Sopenharmony_cistruct nlm_soc_info nlm_nodes[NLM_NR_NODES]; 538c2ecf20Sopenharmony_cicpumask_t nlm_cpumask = CPU_MASK_CPU0; 548c2ecf20Sopenharmony_ciunsigned int nlm_threads_per_core; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistatic void nlm_linux_exit(void) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci uint64_t sysbase = nlm_get_node(0)->sysbase; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci if (cpu_is_xlp9xx()) 618c2ecf20Sopenharmony_ci nlm_write_sys_reg(sysbase, SYS_9XX_CHIP_RESET, 1); 628c2ecf20Sopenharmony_ci else 638c2ecf20Sopenharmony_ci nlm_write_sys_reg(sysbase, SYS_CHIP_RESET, 1); 648c2ecf20Sopenharmony_ci for ( ; ; ) 658c2ecf20Sopenharmony_ci cpu_wait(); 668c2ecf20Sopenharmony_ci} 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic void nlm_fixup_mem(void) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci const int pref_backup = 512; 718c2ecf20Sopenharmony_ci struct memblock_region *mem; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci for_each_mem_region(mem) { 748c2ecf20Sopenharmony_ci memblock_remove(mem->base + mem->size - pref_backup, 758c2ecf20Sopenharmony_ci pref_backup); 768c2ecf20Sopenharmony_ci } 778c2ecf20Sopenharmony_ci} 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistatic void __init xlp_init_mem_from_bars(void) 808c2ecf20Sopenharmony_ci{ 818c2ecf20Sopenharmony_ci uint64_t map[16]; 828c2ecf20Sopenharmony_ci int i, n; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci n = nlm_get_dram_map(-1, map, ARRAY_SIZE(map)); /* -1 : all nodes */ 858c2ecf20Sopenharmony_ci for (i = 0; i < n; i += 2) { 868c2ecf20Sopenharmony_ci /* exclude 0x1000_0000-0x2000_0000, u-boot device */ 878c2ecf20Sopenharmony_ci if (map[i] <= 0x10000000 && map[i+1] > 0x10000000) 888c2ecf20Sopenharmony_ci map[i+1] = 0x10000000; 898c2ecf20Sopenharmony_ci if (map[i] > 0x10000000 && map[i] < 0x20000000) 908c2ecf20Sopenharmony_ci map[i] = 0x20000000; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci memblock_add(map[i], map[i+1] - map[i]); 938c2ecf20Sopenharmony_ci } 948c2ecf20Sopenharmony_ci} 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_civoid __init plat_mem_setup(void) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 998c2ecf20Sopenharmony_ci nlm_wakeup_secondary_cpus(); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci /* update TLB size after waking up threads */ 1028c2ecf20Sopenharmony_ci current_cpu_data.tlbsize = ((read_c0_config6() >> 16) & 0xffff) + 1; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci register_smp_ops(&nlm_smp_ops); 1058c2ecf20Sopenharmony_ci#endif 1068c2ecf20Sopenharmony_ci _machine_restart = (void (*)(char *))nlm_linux_exit; 1078c2ecf20Sopenharmony_ci _machine_halt = nlm_linux_exit; 1088c2ecf20Sopenharmony_ci pm_power_off = nlm_linux_exit; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci /* memory and bootargs from DT */ 1118c2ecf20Sopenharmony_ci xlp_early_init_devtree(); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci if (memblock_end_of_DRAM() == 0) { 1148c2ecf20Sopenharmony_ci pr_info("Using DRAM BARs for memory map.\n"); 1158c2ecf20Sopenharmony_ci xlp_init_mem_from_bars(); 1168c2ecf20Sopenharmony_ci } 1178c2ecf20Sopenharmony_ci /* Calculate and setup wired entries for mapped kernel */ 1188c2ecf20Sopenharmony_ci nlm_fixup_mem(); 1198c2ecf20Sopenharmony_ci} 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ciconst char *get_system_type(void) 1228c2ecf20Sopenharmony_ci{ 1238c2ecf20Sopenharmony_ci switch (read_c0_prid() & PRID_IMP_MASK) { 1248c2ecf20Sopenharmony_ci case PRID_IMP_NETLOGIC_XLP9XX: 1258c2ecf20Sopenharmony_ci case PRID_IMP_NETLOGIC_XLP5XX: 1268c2ecf20Sopenharmony_ci case PRID_IMP_NETLOGIC_XLP2XX: 1278c2ecf20Sopenharmony_ci return "Broadcom XLPII Series"; 1288c2ecf20Sopenharmony_ci default: 1298c2ecf20Sopenharmony_ci return "Netlogic XLP Series"; 1308c2ecf20Sopenharmony_ci } 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_civoid __init prom_free_prom_memory(void) 1348c2ecf20Sopenharmony_ci{ 1358c2ecf20Sopenharmony_ci /* Nothing yet */ 1368c2ecf20Sopenharmony_ci} 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_civoid xlp_mmu_init(void) 1398c2ecf20Sopenharmony_ci{ 1408c2ecf20Sopenharmony_ci u32 conf4; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci if (cpu_is_xlpii()) { 1438c2ecf20Sopenharmony_ci /* XLPII series has extended pagesize in config 4 */ 1448c2ecf20Sopenharmony_ci conf4 = read_c0_config4() & ~0x1f00u; 1458c2ecf20Sopenharmony_ci write_c0_config4(conf4 | ((PAGE_SHIFT - 10) / 2 << 8)); 1468c2ecf20Sopenharmony_ci } else { 1478c2ecf20Sopenharmony_ci /* enable extended TLB and Large Fixed TLB */ 1488c2ecf20Sopenharmony_ci write_c0_config6(read_c0_config6() | 0x24); 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci /* set page mask of extended Fixed TLB in config7 */ 1518c2ecf20Sopenharmony_ci write_c0_config7(PM_DEFAULT_MASK >> 1528c2ecf20Sopenharmony_ci (13 + (ffz(PM_DEFAULT_MASK >> 13) / 2))); 1538c2ecf20Sopenharmony_ci } 1548c2ecf20Sopenharmony_ci} 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_civoid nlm_percpu_init(int hwcpuid) 1578c2ecf20Sopenharmony_ci{ 1588c2ecf20Sopenharmony_ci} 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_civoid __init prom_init(void) 1618c2ecf20Sopenharmony_ci{ 1628c2ecf20Sopenharmony_ci void *reset_vec; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci nlm_io_base = CKSEG1ADDR(XLP_DEFAULT_IO_BASE); 1658c2ecf20Sopenharmony_ci nlm_init_boot_cpu(); 1668c2ecf20Sopenharmony_ci xlp_mmu_init(); 1678c2ecf20Sopenharmony_ci nlm_node_init(0); 1688c2ecf20Sopenharmony_ci xlp_dt_init((void *)(long)fw_arg0); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci /* Update reset entry point with CPU init code */ 1718c2ecf20Sopenharmony_ci reset_vec = (void *)CKSEG1ADDR(RESET_VEC_PHYS); 1728c2ecf20Sopenharmony_ci memset(reset_vec, 0, RESET_VEC_SIZE); 1738c2ecf20Sopenharmony_ci memcpy(reset_vec, (void *)nlm_reset_entry, 1748c2ecf20Sopenharmony_ci (nlm_reset_entry_end - nlm_reset_entry)); 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP 1778c2ecf20Sopenharmony_ci cpumask_setall(&nlm_cpumask); 1788c2ecf20Sopenharmony_ci#endif 1798c2ecf20Sopenharmony_ci} 180