1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
4 * Scott McNutt <smcnutt@psyent.com>
11 #include <asm/cache.h>
13 DECLARE_GLOBAL_DATA_PTR;
15 #ifdef CONFIG_DISPLAY_CPUINFO
16 int print_cpuinfo(void)
18 printf("CPU: Nios-II\n");
21 #endif /* CONFIG_DISPLAY_CPUINFO */
23 #ifdef CONFIG_ALTERA_SYSID
31 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
34 /* indirect call to go beyond 256MB limitation of toolchain */
35 nios2_callr(gd->arch.reset_addr);
40 * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
41 * exception address. Define CONFIG_ROM_STUBS to prevent
42 * the copy (e.g. exception in flash or in other
43 * softare/firmware component).
45 #ifndef CONFIG_ROM_STUBS
46 static void copy_exception_trampoline(void)
48 extern int _except_start, _except_end;
49 void *except_target = (void *)gd->arch.exception_addr;
51 if (&_except_start != except_target) {
52 memcpy(except_target, &_except_start,
53 &_except_end - &_except_start);
54 flush_cache(gd->arch.exception_addr,
55 &_except_end - &_except_start);
60 int arch_cpu_init_dm(void)
65 ret = uclass_first_device_err(UCLASS_CPU, &dev);
69 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
70 #ifndef CONFIG_ROM_STUBS
71 copy_exception_trampoline();
77 static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
79 const char *cpu_name = "Nios-II";
81 if (size < strlen(cpu_name))
83 strcpy(buf, cpu_name);
88 static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info)
90 info->cpu_freq = gd->cpu_clk;
91 info->features = (1 << CPU_FEAT_L1_CACHE) |
92 (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
97 static int altera_nios2_get_count(struct udevice *dev)
102 static int altera_nios2_probe(struct udevice *dev)
104 const void *blob = gd->fdt_blob;
105 int node = dev_of_offset(dev);
107 gd->cpu_clk = fdtdec_get_int(blob, node,
108 "clock-frequency", 0);
109 gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
110 "dcache-line-size", 0);
111 gd->arch.icache_line_size = fdtdec_get_int(blob, node,
112 "icache-line-size", 0);
113 gd->arch.dcache_size = fdtdec_get_int(blob, node,
115 gd->arch.icache_size = fdtdec_get_int(blob, node,
117 gd->arch.reset_addr = fdtdec_get_int(blob, node,
118 "altr,reset-addr", 0);
119 gd->arch.exception_addr = fdtdec_get_int(blob, node,
120 "altr,exception-addr", 0);
121 gd->arch.has_initda = fdtdec_get_int(blob, node,
122 "altr,has-initda", 0);
123 gd->arch.has_mmu = fdtdec_get_int(blob, node,
125 gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000;
126 gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000;
127 gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff;
132 static const struct cpu_ops altera_nios2_ops = {
133 .get_desc = altera_nios2_get_desc,
134 .get_info = altera_nios2_get_info,
135 .get_count = altera_nios2_get_count,
138 static const struct udevice_id altera_nios2_ids[] = {
139 { .compatible = "altr,nios2-1.0" },
140 { .compatible = "altr,nios2-1.1" },
144 U_BOOT_DRIVER(altera_nios2) = {
145 .name = "altera_nios2",
147 .of_match = altera_nios2_ids,
148 .probe = altera_nios2_probe,
149 .ops = &altera_nios2_ops,
150 .flags = DM_FLAG_PRE_RELOC,
153 /* This is a dummy function on nios2 */