Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * This file is subject to the terms and conditions of the GNU General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Public License.  See the file "COPYING" in the main directory of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * archive for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2000 - 2001 by Kanoj Sarcar (kanoj@sgi.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2000 - 2001 by Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <asm/bootinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/sgialib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <asm/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/sn/agent.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/sn/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/sn/klconfig.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/sn/ioc3.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/mipsregs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/sn/gda.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <asm/sn/intr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <asm/current.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/thread_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <asm/sn/launch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <asm/sn/mapped_kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include "ip27-common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define CPU_NONE		(cpuid_t)-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static DECLARE_BITMAP(hub_init_mask, MAX_NUMNODES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) nasid_t master_nasid = INVALID_NASID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) struct cpuinfo_ip27 sn_cpu_info[NR_CPUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) EXPORT_SYMBOL_GPL(sn_cpu_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static void per_hub_init(nasid_t nasid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct hub_data *hub = hub_data(nasid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	cpumask_set_cpu(smp_processor_id(), &hub->h_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (test_and_set_bit(nasid, hub_init_mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	 * Set CRB timeout at 5ms, (< PI timeout of 10ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	REMOTE_HUB_S(nasid, IIO_ICTP, 0x800);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	REMOTE_HUB_S(nasid, IIO_ICTO, 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	hub_rtc_init(nasid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	if (nasid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		/* copy exception handlers from first node to current node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		memcpy((void *)NODE_OFFSET_TO_K0(nasid, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		       (void *)CKSEG0, 0x200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		__flush_cache_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		/* switch to node local exception handlers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		REMOTE_HUB_S(nasid, PI_CALIAS_SIZE, PI_CALIAS_SIZE_8K);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) void per_cpu_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	nasid_t nasid = get_nasid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	clear_c0_status(ST0_IM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	per_hub_init(nasid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	pr_info("CPU %d clock is %dMHz.\n", cpu, sn_cpu_info[cpu].p_speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	install_ipi();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	/* Install our NMI handler if symmon hasn't installed one. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	install_cpu_nmi_handler(cputoslice(cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	enable_percpu_irq(IP27_HUB_PEND0_IRQ, IRQ_TYPE_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	enable_percpu_irq(IP27_HUB_PEND1_IRQ, IRQ_TYPE_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) void __init plat_mem_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	u64 p, e, n_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	nasid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	register_smp_ops(&ip27_smp_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	ip27_reboot_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	 * hub_rtc init and cpu clock intr enabled for later calibrate_delay.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	nid = get_nasid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	printk("IP27: Running on node %d.\n", nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	p = LOCAL_HUB_L(PI_CPU_PRESENT_A) & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	e = LOCAL_HUB_L(PI_CPU_ENABLE_A) & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	printk("Node %d has %s primary CPU%s.\n", nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	       p ? "a" : "no",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	       e ? ", CPU is running" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	p = LOCAL_HUB_L(PI_CPU_PRESENT_B) & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	e = LOCAL_HUB_L(PI_CPU_ENABLE_B) & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	printk("Node %d has %s secondary CPU%s.\n", nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	       p ? "a" : "no",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	       e ? ", CPU is running" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	 * Try to catch kernel missconfigurations and give user an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * indication what option to select.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	n_mode = LOCAL_HUB_L(NI_STATUS_REV_ID) & NSRI_MORENODES_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	printk("Machine is in %c mode.\n", n_mode ? 'N' : 'M');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #ifdef CONFIG_SGI_SN_N_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (!n_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		panic("Kernel compiled for M mode.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	if (n_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		panic("Kernel compiled for N mode.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	ioport_resource.start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	ioport_resource.end = ~0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	set_io_port_base(IO_BASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) const char *get_system_type(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return "SGI Origin";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) void __init prom_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	prom_init_cmdline(fw_arg0, (LONG *)fw_arg1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	prom_meminit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)