drm/panthor: Don't add write fences to the shared BOs
[drm/drm-misc.git] / arch / mips / loongson64 / init.c
bloba35dd731179582f981de5517ee827295d6796173
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2009 Lemote Inc.
4 * Author: Wu Zhangjin, wuzhangjin@gmail.com
5 */
7 #include <linux/irqchip.h>
8 #include <linux/logic_pio.h>
9 #include <linux/memblock.h>
10 #include <linux/of.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>
18 #include <loongson.h>
19 #include <boot_param.h>
21 #define NODE_ID_OFFSET_ADDR ((void __iomem *)TO_UNCAC(0x1001041c))
23 u32 node_id_offset;
25 static void __init mips_nmi_setup(void)
27 void *base;
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)
41 node_id_offset = 37;
44 void virtual_early_config(void)
46 node_id_offset = 44;
49 void __init szmem(unsigned int node)
51 u32 i, mem_type;
52 phys_addr_t node_id, mem_start, mem_size;
54 /* Otherwise come from DTB */
55 if (loongson_sysconf.fw_interface != LOONGSON_LEFI)
56 return;
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;
61 if (node_id != node)
62 continue;
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;
70 else
71 mem_size = mem_size << 20;
73 mem_start = (node_id << 44) | loongson_memmap->map[i].mem_start;
75 switch (mem_type) {
76 case SYSTEM_RAM_LOW:
77 case SYSTEM_RAM_HIGH:
78 case UMA_VIDEO_RAM:
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,
82 MEMBLOCK_NONE);
83 break;
84 case SYSTEM_RAM_RESERVED:
85 case VIDEO_ROM:
86 case ADAPTER_ROM:
87 case ACPI_TABLE:
88 case SMBIOS_TABLE:
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);
92 break;
93 /* We should not reserve VUMA_VIDEO_RAM as it overlaps with MMIO */
94 case VUMA_VIDEO_RAM:
95 default:
96 pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes unhandled\n",
97 (u32)node_id, mem_type, &mem_start, &mem_size);
98 break;
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),
105 SZ_256K);
106 /* set nid for reserved memory */
107 memblock_set_node((u64)node << 44, (u64)(node + 1) << 44,
108 &memblock.reserved, node);
111 #ifndef CONFIG_NUMA
112 static void __init prom_init_memory(void)
114 szmem(0);
116 #endif
118 void __init prom_init(void)
120 fw_init_cmdline();
122 if (fw_arg2 == 0 || (fdt_magic(fw_arg2) == FDT_MAGIC)) {
123 loongson_sysconf.fw_interface = LOONGSON_DTB;
124 prom_dtb_init_env();
125 } else {
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();
136 #ifdef CONFIG_NUMA
137 prom_init_numa_memory();
138 #else
139 prom_init_memory();
140 #endif
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);
145 else
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)
155 int ret = 0;
156 struct logic_pio_hwaddr *range;
157 unsigned long vaddr;
159 range = kzalloc(sizeof(*range), GFP_ATOMIC);
160 if (!range)
161 return -ENOMEM;
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);
169 if (ret) {
170 kfree(range);
171 return ret;
174 /* Legacy ISA must placed at the start of PCI_IOBASE */
175 if (range->io_start != 0) {
176 logic_pio_unregister_range(range);
177 kfree(range);
178 return -EINVAL;
181 vaddr = PCI_IOBASE + range->io_start;
183 vmap_page_range(vaddr, vaddr + size, hw_start, pgprot_device(PAGE_KERNEL));
185 return 0;
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");
200 of_node_put(np);
201 break;
204 for_each_of_range(&parser, &range) {
205 switch (range.flags & IORESOURCE_TYPE_BITS) {
206 case IORESOURCE_IO:
207 pr_info(" IO 0x%016llx..0x%016llx -> 0x%016llx\n",
208 range.cpu_addr,
209 range.cpu_addr + range.size - 1,
210 range.bus_addr);
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");
213 break;
214 case IORESOURCE_MEM:
215 pr_info(" MEM 0x%016llx..0x%016llx -> 0x%016llx\n",
216 range.cpu_addr,
217 range.cpu_addr + range.size - 1,
218 range.bus_addr);
219 break;
225 void __init arch_init_irq(void)
227 reserve_pio_range();
228 irqchip_init();