xref: /openbmc/linux/arch/mips/loongson64/init.c (revision 82df5b73)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2009 Lemote Inc.
4  * Author: Wu Zhangjin, wuzhangjin@gmail.com
5  */
6 
7 #include <linux/irqchip.h>
8 #include <linux/logic_pio.h>
9 #include <linux/memblock.h>
10 #include <asm/bootinfo.h>
11 #include <asm/traps.h>
12 #include <asm/smp-ops.h>
13 #include <asm/cacheflush.h>
14 #include <asm/fw/fw.h>
15 
16 #include <loongson.h>
17 #include <boot_param.h>
18 
19 #define NODE_ID_OFFSET_ADDR	((void __iomem *)TO_UNCAC(0x1001041c))
20 
21 u32 node_id_offset;
22 
23 static void __init mips_nmi_setup(void)
24 {
25 	void *base;
26 	extern char except_vec_nmi[];
27 
28 	base = (void *)(CAC_BASE + 0x380);
29 	memcpy(base, except_vec_nmi, 0x80);
30 	flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
31 }
32 
33 void ls7a_early_config(void)
34 {
35 	node_id_offset = ((readl(NODE_ID_OFFSET_ADDR) >> 8) & 0x1f) + 36;
36 }
37 
38 void rs780e_early_config(void)
39 {
40 	node_id_offset = 37;
41 }
42 
43 void __init prom_init(void)
44 {
45 	fw_init_cmdline();
46 	prom_init_env();
47 
48 	/* init base address of io space */
49 	set_io_port_base(PCI_IOBASE);
50 
51 	loongson_sysconf.early_config();
52 
53 	prom_init_numa_memory();
54 
55 	/* Hardcode to CPU UART 0 */
56 	setup_8250_early_printk_port(TO_UNCAC(LOONGSON_REG_BASE + 0x1e0), 0, 1024);
57 
58 	register_smp_ops(&loongson3_smp_ops);
59 	board_nmi_handler_setup = mips_nmi_setup;
60 }
61 
62 void __init prom_free_prom_memory(void)
63 {
64 }
65 
66 static __init void reserve_pio_range(void)
67 {
68 	struct logic_pio_hwaddr *range;
69 
70 	range = kzalloc(sizeof(*range), GFP_ATOMIC);
71 	if (!range)
72 		return;
73 
74 	range->fwnode = &of_root->fwnode;
75 	range->size = MMIO_LOWER_RESERVED;
76 	range->hw_start = LOONGSON_PCIIO_BASE;
77 	range->flags = LOGIC_PIO_CPU_MMIO;
78 
79 	if (logic_pio_register_range(range)) {
80 		pr_err("Failed to reserve PIO range for legacy ISA\n");
81 		goto free_range;
82 	}
83 
84 	if (WARN(range->io_start != 0,
85 			"Reserved PIO range does not start from 0\n"))
86 		goto unregister;
87 
88 	/*
89 	 * i8259 would access I/O space, so mapping must be done here.
90 	 * Please remove it when all drivers can be managed by logic_pio.
91 	 */
92 	ioremap_page_range(PCI_IOBASE, PCI_IOBASE + MMIO_LOWER_RESERVED,
93 				LOONGSON_PCIIO_BASE,
94 				pgprot_device(PAGE_KERNEL));
95 
96 	return;
97 unregister:
98 	logic_pio_unregister_range(range);
99 free_range:
100 	kfree(range);
101 }
102 
103 void __init arch_init_irq(void)
104 {
105 	reserve_pio_range();
106 	irqchip_init();
107 }
108