wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, <wd@denx.de> |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
Shinya Kuribayashi | 93971f6 | 2008-10-19 12:08:50 +0900 | [diff] [blame] | 10 | #include <netdev.h> |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 11 | #include <asm/mipsregs.h> |
Shinya Kuribayashi | d784e4e | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 12 | #include <asm/cacheops.h> |
Shinya Kuribayashi | 56be1dd | 2008-03-25 21:30:07 +0900 | [diff] [blame] | 13 | #include <asm/reboot.h> |
Shinya Kuribayashi | d784e4e | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 14 | |
| 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))) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 24 | |
Shinya Kuribayashi | 56be1dd | 2008-03-25 21:30:07 +0900 | [diff] [blame] | 25 | void __attribute__((weak)) _machine_restart(void) |
| 26 | { |
| 27 | } |
| 28 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 29 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 30 | { |
Shinya Kuribayashi | 56be1dd | 2008-03-25 21:30:07 +0900 | [diff] [blame] | 31 | _machine_restart(); |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 32 | |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 33 | fprintf(stderr, "*** reset failed ***\n"); |
| 34 | return 0; |
| 35 | } |
| 36 | |
Paul Burton | f122b5a | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 37 | #ifdef CONFIG_SYS_CACHELINE_SIZE |
| 38 | |
| 39 | static inline unsigned long icache_line_size(void) |
| 40 | { |
| 41 | return CONFIG_SYS_CACHELINE_SIZE; |
| 42 | } |
| 43 | |
| 44 | static inline unsigned long dcache_line_size(void) |
| 45 | { |
| 46 | return CONFIG_SYS_CACHELINE_SIZE; |
| 47 | } |
| 48 | |
| 49 | #else /* !CONFIG_SYS_CACHELINE_SIZE */ |
| 50 | |
| 51 | static 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 | |
| 61 | static 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 Kuribayashi | c7faac5 | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 73 | void flush_cache(ulong start_addr, ulong size) |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 74 | { |
Paul Burton | f122b5a | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 75 | unsigned long ilsize = icache_line_size(); |
| 76 | unsigned long dlsize = dcache_line_size(); |
| 77 | unsigned long addr, aend; |
Shinya Kuribayashi | d784e4e | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 78 | |
Yao Cheng | acf5117 | 2011-08-10 15:11:16 +0800 | [diff] [blame] | 79 | /* aend will be miscalculated when size is zero, so we return here */ |
| 80 | if (size == 0) |
| 81 | return; |
| 82 | |
Paul Burton | f122b5a | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 83 | 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 Kuribayashi | d784e4e | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 99 | while (1) { |
Zhi-zhou Zhang | 724f618 | 2012-10-16 15:02:08 +0200 | [diff] [blame] | 100 | cache_op(HIT_WRITEBACK_INV_D, addr); |
Paul Burton | f122b5a | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 101 | 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 Zhang | 724f618 | 2012-10-16 15:02:08 +0200 | [diff] [blame] | 110 | cache_op(HIT_INVALIDATE_I, addr); |
Shinya Kuribayashi | d784e4e | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 111 | if (addr == aend) |
| 112 | break; |
Paul Burton | f122b5a | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 113 | addr += ilsize; |
Shinya Kuribayashi | d784e4e | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 114 | } |
wdenk | bb1b826 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 115 | } |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 116 | |
Stefan Roese | 9bf63bf | 2009-01-21 17:20:20 +0100 | [diff] [blame] | 117 | void flush_dcache_range(ulong start_addr, ulong stop) |
| 118 | { |
Paul Burton | f122b5a | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 119 | unsigned long lsize = dcache_line_size(); |
Stefan Roese | 9bf63bf | 2009-01-21 17:20:20 +0100 | [diff] [blame] | 120 | unsigned long addr = start_addr & ~(lsize - 1); |
| 121 | unsigned long aend = (stop - 1) & ~(lsize - 1); |
| 122 | |
| 123 | while (1) { |
Zhi-zhou Zhang | 724f618 | 2012-10-16 15:02:08 +0200 | [diff] [blame] | 124 | cache_op(HIT_WRITEBACK_INV_D, addr); |
Stefan Roese | 9bf63bf | 2009-01-21 17:20:20 +0100 | [diff] [blame] | 125 | if (addr == aend) |
| 126 | break; |
| 127 | addr += lsize; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | void invalidate_dcache_range(ulong start_addr, ulong stop) |
| 132 | { |
Paul Burton | f122b5a | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 133 | unsigned long lsize = dcache_line_size(); |
Stefan Roese | 9bf63bf | 2009-01-21 17:20:20 +0100 | [diff] [blame] | 134 | unsigned long addr = start_addr & ~(lsize - 1); |
| 135 | unsigned long aend = (stop - 1) & ~(lsize - 1); |
| 136 | |
| 137 | while (1) { |
Zhi-zhou Zhang | 724f618 | 2012-10-16 15:02:08 +0200 | [diff] [blame] | 138 | cache_op(HIT_INVALIDATE_D, addr); |
Stefan Roese | 9bf63bf | 2009-01-21 17:20:20 +0100 | [diff] [blame] | 139 | if (addr == aend) |
| 140 | break; |
| 141 | addr += lsize; |
| 142 | } |
| 143 | } |
| 144 | |
Shinya Kuribayashi | c7faac5 | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 145 | void write_one_tlb(int index, u32 pagemask, u32 hi, u32 low0, u32 low1) |
| 146 | { |
Shinya Kuribayashi | 0fdd27e | 2008-05-30 00:53:38 +0900 | [diff] [blame] | 147 | write_c0_entrylo0(low0); |
| 148 | write_c0_pagemask(pagemask); |
| 149 | write_c0_entrylo1(low1); |
| 150 | write_c0_entryhi(hi); |
| 151 | write_c0_index(index); |
wdenk | 9b7f384 | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 152 | tlb_write_indexed(); |
| 153 | } |
Shinya Kuribayashi | 93971f6 | 2008-10-19 12:08:50 +0900 | [diff] [blame] | 154 | |
| 155 | int cpu_eth_init(bd_t *bis) |
| 156 | { |
| 157 | #ifdef CONFIG_SOC_AU1X00 |
| 158 | au1x00_enet_initialize(bis); |
| 159 | #endif |
| 160 | return 0; |
| 161 | } |