blob: 278865b6fff54849c98b0e1bd69a7cc7b2e5ba6f [file] [log] [blame]
wdenkc0218802003-03-27 12:09:35 +00001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc0218802003-03-27 12:09:35 +00006 */
7
8#include <common.h>
9#include <command.h>
Shinya Kuribayashi5dfb3ee2008-10-19 12:08:50 +090010#include <netdev.h>
wdenk5da627a2003-10-09 20:09:04 +000011#include <asm/mipsregs.h>
Shinya Kuribayashiccf8f822008-03-25 21:30:06 +090012#include <asm/cacheops.h>
Shinya Kuribayashib0c66af2008-03-25 21:30:07 +090013#include <asm/reboot.h>
Shinya Kuribayashiccf8f822008-03-25 21:30:06 +090014
15#define cache_op(op,addr) \
16 __asm__ __volatile__( \
17 " .set push \n" \
18 " .set noreorder \n" \
19 " .set mips3\n\t \n" \
20 " cache %0, %1 \n" \
21 " .set pop \n" \
22 : \
23 : "i" (op), "R" (*(unsigned char *)(addr)))
wdenkc0218802003-03-27 12:09:35 +000024
Shinya Kuribayashib0c66af2008-03-25 21:30:07 +090025void __attribute__((weak)) _machine_restart(void)
26{
27}
28
Wolfgang Denk54841ab2010-06-28 22:00:46 +020029int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenkc0218802003-03-27 12:09:35 +000030{
Shinya Kuribayashib0c66af2008-03-25 21:30:07 +090031 _machine_restart();
wdenk3e386912003-04-05 00:53:31 +000032
wdenkc0218802003-03-27 12:09:35 +000033 fprintf(stderr, "*** reset failed ***\n");
34 return 0;
35}
36
Paul Burtonfa476f72013-11-08 11:18:42 +000037#ifdef CONFIG_SYS_CACHELINE_SIZE
38
39static inline unsigned long icache_line_size(void)
40{
41 return CONFIG_SYS_CACHELINE_SIZE;
42}
43
44static inline unsigned long dcache_line_size(void)
45{
46 return CONFIG_SYS_CACHELINE_SIZE;
47}
48
49#else /* !CONFIG_SYS_CACHELINE_SIZE */
50
51static inline unsigned long icache_line_size(void)
52{
53 unsigned long conf1, il;
54 conf1 = read_c0_config1();
55 il = (conf1 & MIPS_CONF1_IL) >> MIPS_CONF1_IL_SHIFT;
56 if (!il)
57 return 0;
58 return 2 << il;
59}
60
61static inline unsigned long dcache_line_size(void)
62{
63 unsigned long conf1, dl;
64 conf1 = read_c0_config1();
65 dl = (conf1 & MIPS_CONF1_DL) >> MIPS_CONF1_DL_SHIFT;
66 if (!dl)
67 return 0;
68 return 2 << dl;
69}
70
71#endif /* !CONFIG_SYS_CACHELINE_SIZE */
72
Shinya Kuribayashi03c031d2007-10-27 15:27:06 +090073void flush_cache(ulong start_addr, ulong size)
wdenkc0218802003-03-27 12:09:35 +000074{
Paul Burtonfa476f72013-11-08 11:18:42 +000075 unsigned long ilsize = icache_line_size();
76 unsigned long dlsize = dcache_line_size();
77 unsigned long addr, aend;
Shinya Kuribayashiccf8f822008-03-25 21:30:06 +090078
Yao Chengdc344582011-08-10 15:11:16 +080079 /* aend will be miscalculated when size is zero, so we return here */
80 if (size == 0)
81 return;
82
Paul Burtonfa476f72013-11-08 11:18:42 +000083 addr = start_addr & ~(dlsize - 1);
84 aend = (start_addr + size - 1) & ~(dlsize - 1);
85
86 if (ilsize == dlsize) {
87 /* flush I-cache & D-cache simultaneously */
88 while (1) {
89 cache_op(HIT_WRITEBACK_INV_D, addr);
90 cache_op(HIT_INVALIDATE_I, addr);
91 if (addr == aend)
92 break;
93 addr += dlsize;
94 }
95 return;
96 }
97
98 /* flush D-cache */
Shinya Kuribayashiccf8f822008-03-25 21:30:06 +090099 while (1) {
Zhi-zhou Zhangcb0a6a12012-10-16 15:02:08 +0200100 cache_op(HIT_WRITEBACK_INV_D, addr);
Paul Burtonfa476f72013-11-08 11:18:42 +0000101 if (addr == aend)
102 break;
103 addr += dlsize;
104 }
105
106 /* flush I-cache */
107 addr = start_addr & ~(ilsize - 1);
108 aend = (start_addr + size - 1) & ~(ilsize - 1);
109 while (1) {
Zhi-zhou Zhangcb0a6a12012-10-16 15:02:08 +0200110 cache_op(HIT_INVALIDATE_I, addr);
Shinya Kuribayashiccf8f822008-03-25 21:30:06 +0900111 if (addr == aend)
112 break;
Paul Burtonfa476f72013-11-08 11:18:42 +0000113 addr += ilsize;
Shinya Kuribayashiccf8f822008-03-25 21:30:06 +0900114 }
wdenkc0218802003-03-27 12:09:35 +0000115}
wdenk5da627a2003-10-09 20:09:04 +0000116
Stefan Roese03d3bfb2009-01-21 17:20:20 +0100117void flush_dcache_range(ulong start_addr, ulong stop)
118{
Paul Burtonfa476f72013-11-08 11:18:42 +0000119 unsigned long lsize = dcache_line_size();
Stefan Roese03d3bfb2009-01-21 17:20:20 +0100120 unsigned long addr = start_addr & ~(lsize - 1);
121 unsigned long aend = (stop - 1) & ~(lsize - 1);
122
123 while (1) {
Zhi-zhou Zhangcb0a6a12012-10-16 15:02:08 +0200124 cache_op(HIT_WRITEBACK_INV_D, addr);
Stefan Roese03d3bfb2009-01-21 17:20:20 +0100125 if (addr == aend)
126 break;
127 addr += lsize;
128 }
129}
130
131void invalidate_dcache_range(ulong start_addr, ulong stop)
132{
Paul Burtonfa476f72013-11-08 11:18:42 +0000133 unsigned long lsize = dcache_line_size();
Stefan Roese03d3bfb2009-01-21 17:20:20 +0100134 unsigned long addr = start_addr & ~(lsize - 1);
135 unsigned long aend = (stop - 1) & ~(lsize - 1);
136
137 while (1) {
Zhi-zhou Zhangcb0a6a12012-10-16 15:02:08 +0200138 cache_op(HIT_INVALIDATE_D, addr);
Stefan Roese03d3bfb2009-01-21 17:20:20 +0100139 if (addr == aend)
140 break;
141 addr += lsize;
142 }
143}
144
Shinya Kuribayashi03c031d2007-10-27 15:27:06 +0900145void write_one_tlb(int index, u32 pagemask, u32 hi, u32 low0, u32 low1)
146{
Shinya Kuribayashie2ad8422008-05-30 00:53:38 +0900147 write_c0_entrylo0(low0);
148 write_c0_pagemask(pagemask);
149 write_c0_entrylo1(low1);
150 write_c0_entryhi(hi);
151 write_c0_index(index);
wdenk5da627a2003-10-09 20:09:04 +0000152 tlb_write_indexed();
153}
Shinya Kuribayashi5dfb3ee2008-10-19 12:08:50 +0900154
155int cpu_eth_init(bd_t *bis)
156{
157#ifdef CONFIG_SOC_AU1X00
158 au1x00_enet_initialize(bis);
159#endif
160 return 0;
161}