1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2009 Lemote Inc.
4 * Author: Wu Zhangjin, wuzhangjin@gmail.com
7 #include <linux/irqchip.h>
8 #include <linux/logic_pio.h>
9 #include <linux/memblock.h>
11 #include <linux/of_address.h>
12 #include <asm/bootinfo.h>
13 #include <asm/traps.h>
14 #include <asm/smp-ops.h>
15 #include <asm/cacheflush.h>
16 #include <asm/fw/fw.h>
19 #include <boot_param.h>
21 #define NODE_ID_OFFSET_ADDR ((void __iomem *)TO_UNCAC(0x1001041c))
25 static void __init
mips_nmi_setup(void)
29 base
= (void *)(CAC_BASE
+ 0x380);
30 memcpy(base
, except_vec_nmi
, 0x80);
31 flush_icache_range((unsigned long)base
, (unsigned long)base
+ 0x80);
34 void ls7a_early_config(void)
36 node_id_offset
= ((readl(NODE_ID_OFFSET_ADDR
) >> 8) & 0x1f) + 36;
39 void rs780e_early_config(void)
44 void virtual_early_config(void)
49 void __init
szmem(unsigned int node
)
52 phys_addr_t node_id
, mem_start
, mem_size
;
54 /* Otherwise come from DTB */
55 if (loongson_sysconf
.fw_interface
!= LOONGSON_LEFI
)
58 /* Parse memory information and activate */
59 for (i
= 0; i
< loongson_memmap
->nr_map
; i
++) {
60 node_id
= loongson_memmap
->map
[i
].node_id
;
64 mem_type
= loongson_memmap
->map
[i
].mem_type
;
65 mem_size
= loongson_memmap
->map
[i
].mem_size
;
67 /* Memory size comes in MB if MEM_SIZE_IS_IN_BYTES not set */
68 if (mem_size
& MEM_SIZE_IS_IN_BYTES
)
69 mem_size
&= ~MEM_SIZE_IS_IN_BYTES
;
71 mem_size
= mem_size
<< 20;
73 mem_start
= (node_id
<< 44) | loongson_memmap
->map
[i
].mem_start
;
79 pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes usable\n",
80 (u32
)node_id
, mem_type
, &mem_start
, &mem_size
);
81 memblock_add_node(mem_start
, mem_size
, node
,
84 case SYSTEM_RAM_RESERVED
:
89 pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes reserved\n",
90 (u32
)node_id
, mem_type
, &mem_start
, &mem_size
);
91 memblock_reserve(mem_start
, mem_size
);
93 /* We should not reserve VUMA_VIDEO_RAM as it overlaps with MMIO */
96 pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes unhandled\n",
97 (u32
)node_id
, mem_type
, &mem_start
, &mem_size
);
102 /* Reserve vgabios if it comes from firmware */
103 if (loongson_sysconf
.vgabios_addr
)
104 memblock_reserve(virt_to_phys((void *)loongson_sysconf
.vgabios_addr
),
106 /* set nid for reserved memory */
107 memblock_set_node((u64
)node
<< 44, (u64
)(node
+ 1) << 44,
108 &memblock
.reserved
, node
);
112 static void __init
prom_init_memory(void)
118 void __init
prom_init(void)
122 if (fw_arg2
== 0 || (fdt_magic(fw_arg2
) == FDT_MAGIC
)) {
123 loongson_sysconf
.fw_interface
= LOONGSON_DTB
;
126 loongson_sysconf
.fw_interface
= LOONGSON_LEFI
;
127 prom_lefi_init_env();
130 /* init base address of io space */
131 set_io_port_base(PCI_IOBASE
);
133 if (loongson_sysconf
.early_config
)
134 loongson_sysconf
.early_config();
137 prom_init_numa_memory();
142 /* Hardcode to CPU UART 0 */
143 if ((read_c0_prid() & PRID_IMP_MASK
) == PRID_IMP_LOONGSON_64R
)
144 setup_8250_early_printk_port(TO_UNCAC(LOONGSON_REG_BASE
), 0, 1024);
146 setup_8250_early_printk_port(TO_UNCAC(LOONGSON_REG_BASE
+ 0x1e0), 0, 1024);
148 register_smp_ops(&loongson3_smp_ops
);
149 board_nmi_handler_setup
= mips_nmi_setup
;
152 static int __init
add_legacy_isa_io(struct fwnode_handle
*fwnode
, resource_size_t hw_start
,
153 resource_size_t size
)
156 struct logic_pio_hwaddr
*range
;
159 range
= kzalloc(sizeof(*range
), GFP_ATOMIC
);
163 range
->fwnode
= fwnode
;
164 range
->size
= size
= round_up(size
, PAGE_SIZE
);
165 range
->hw_start
= hw_start
;
166 range
->flags
= LOGIC_PIO_CPU_MMIO
;
168 ret
= logic_pio_register_range(range
);
174 /* Legacy ISA must placed at the start of PCI_IOBASE */
175 if (range
->io_start
!= 0) {
176 logic_pio_unregister_range(range
);
181 vaddr
= PCI_IOBASE
+ range
->io_start
;
183 vmap_page_range(vaddr
, vaddr
+ size
, hw_start
, pgprot_device(PAGE_KERNEL
));
188 static __init
void reserve_pio_range(void)
190 struct device_node
*np
;
192 for_each_node_by_name(np
, "isa") {
193 struct of_range range
;
194 struct of_range_parser parser
;
196 pr_info("ISA Bridge: %pOF\n", np
);
198 if (of_range_parser_init(&parser
, np
)) {
199 pr_info("Failed to parse resources.\n");
204 for_each_of_range(&parser
, &range
) {
205 switch (range
.flags
& IORESOURCE_TYPE_BITS
) {
207 pr_info(" IO 0x%016llx..0x%016llx -> 0x%016llx\n",
209 range
.cpu_addr
+ range
.size
- 1,
211 if (add_legacy_isa_io(&np
->fwnode
, range
.cpu_addr
, range
.size
))
212 pr_warn("Failed to reserve legacy IO in Logic PIO\n");
215 pr_info(" MEM 0x%016llx..0x%016llx -> 0x%016llx\n",
217 range
.cpu_addr
+ range
.size
- 1,
225 void __init
arch_init_irq(void)