wdenk | c021880 | 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 | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
Shinya Kuribayashi | 5dfb3ee | 2008-10-19 12:08:50 +0900 | [diff] [blame] | 10 | #include <netdev.h> |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 11 | #include <asm/mipsregs.h> |
Shinya Kuribayashi | ccf8f82 | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 12 | #include <asm/cacheops.h> |
Shinya Kuribayashi | b0c66af | 2008-03-25 21:30:07 +0900 | [diff] [blame] | 13 | #include <asm/reboot.h> |
Shinya Kuribayashi | ccf8f82 | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 14 | |
Shinya Kuribayashi | b0c66af | 2008-03-25 21:30:07 +0900 | [diff] [blame] | 15 | void __attribute__((weak)) _machine_restart(void) |
| 16 | { |
| 17 | } |
| 18 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 19 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 20 | { |
Shinya Kuribayashi | b0c66af | 2008-03-25 21:30:07 +0900 | [diff] [blame] | 21 | _machine_restart(); |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 22 | |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 23 | fprintf(stderr, "*** reset failed ***\n"); |
| 24 | return 0; |
| 25 | } |
| 26 | |
Paul Burton | fa476f7 | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 27 | #ifdef CONFIG_SYS_CACHELINE_SIZE |
| 28 | |
| 29 | static inline unsigned long icache_line_size(void) |
| 30 | { |
| 31 | return CONFIG_SYS_CACHELINE_SIZE; |
| 32 | } |
| 33 | |
| 34 | static inline unsigned long dcache_line_size(void) |
| 35 | { |
| 36 | return CONFIG_SYS_CACHELINE_SIZE; |
| 37 | } |
| 38 | |
| 39 | #else /* !CONFIG_SYS_CACHELINE_SIZE */ |
| 40 | |
| 41 | static inline unsigned long icache_line_size(void) |
| 42 | { |
| 43 | unsigned long conf1, il; |
| 44 | conf1 = read_c0_config1(); |
| 45 | il = (conf1 & MIPS_CONF1_IL) >> MIPS_CONF1_IL_SHIFT; |
| 46 | if (!il) |
| 47 | return 0; |
| 48 | return 2 << il; |
| 49 | } |
| 50 | |
| 51 | static inline unsigned long dcache_line_size(void) |
| 52 | { |
| 53 | unsigned long conf1, dl; |
| 54 | conf1 = read_c0_config1(); |
| 55 | dl = (conf1 & MIPS_CONF1_DL) >> MIPS_CONF1_DL_SHIFT; |
| 56 | if (!dl) |
| 57 | return 0; |
| 58 | return 2 << dl; |
| 59 | } |
| 60 | |
| 61 | #endif /* !CONFIG_SYS_CACHELINE_SIZE */ |
| 62 | |
Shinya Kuribayashi | 03c031d | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 63 | void flush_cache(ulong start_addr, ulong size) |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 64 | { |
Paul Burton | fa476f7 | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 65 | unsigned long ilsize = icache_line_size(); |
| 66 | unsigned long dlsize = dcache_line_size(); |
Paul Burton | 2b8bcc5 | 2015-01-29 01:27:56 +0000 | [diff] [blame^] | 67 | const void *addr, *aend; |
Shinya Kuribayashi | ccf8f82 | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 68 | |
Yao Cheng | dc34458 | 2011-08-10 15:11:16 +0800 | [diff] [blame] | 69 | /* aend will be miscalculated when size is zero, so we return here */ |
| 70 | if (size == 0) |
| 71 | return; |
| 72 | |
Paul Burton | 2b8bcc5 | 2015-01-29 01:27:56 +0000 | [diff] [blame^] | 73 | addr = (const void *)(start_addr & ~(dlsize - 1)); |
| 74 | aend = (const void *)((start_addr + size - 1) & ~(dlsize - 1)); |
Paul Burton | fa476f7 | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 75 | |
| 76 | if (ilsize == dlsize) { |
| 77 | /* flush I-cache & D-cache simultaneously */ |
| 78 | while (1) { |
Paul Burton | 2b8bcc5 | 2015-01-29 01:27:56 +0000 | [diff] [blame^] | 79 | mips_cache(HIT_WRITEBACK_INV_D, addr); |
| 80 | mips_cache(HIT_INVALIDATE_I, addr); |
Paul Burton | fa476f7 | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 81 | if (addr == aend) |
| 82 | break; |
| 83 | addr += dlsize; |
| 84 | } |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | /* flush D-cache */ |
Shinya Kuribayashi | ccf8f82 | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 89 | while (1) { |
Paul Burton | 2b8bcc5 | 2015-01-29 01:27:56 +0000 | [diff] [blame^] | 90 | mips_cache(HIT_WRITEBACK_INV_D, addr); |
Paul Burton | fa476f7 | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 91 | if (addr == aend) |
| 92 | break; |
| 93 | addr += dlsize; |
| 94 | } |
| 95 | |
| 96 | /* flush I-cache */ |
Paul Burton | 2b8bcc5 | 2015-01-29 01:27:56 +0000 | [diff] [blame^] | 97 | addr = (const void *)(start_addr & ~(ilsize - 1)); |
| 98 | aend = (const void *)((start_addr + size - 1) & ~(ilsize - 1)); |
Paul Burton | fa476f7 | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 99 | while (1) { |
Paul Burton | 2b8bcc5 | 2015-01-29 01:27:56 +0000 | [diff] [blame^] | 100 | mips_cache(HIT_INVALIDATE_I, addr); |
Shinya Kuribayashi | ccf8f82 | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 101 | if (addr == aend) |
| 102 | break; |
Paul Burton | fa476f7 | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 103 | addr += ilsize; |
Shinya Kuribayashi | ccf8f82 | 2008-03-25 21:30:06 +0900 | [diff] [blame] | 104 | } |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 105 | } |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 106 | |
Stefan Roese | 03d3bfb | 2009-01-21 17:20:20 +0100 | [diff] [blame] | 107 | void flush_dcache_range(ulong start_addr, ulong stop) |
| 108 | { |
Paul Burton | fa476f7 | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 109 | unsigned long lsize = dcache_line_size(); |
Paul Burton | 2b8bcc5 | 2015-01-29 01:27:56 +0000 | [diff] [blame^] | 110 | const void *addr = (const void *)(start_addr & ~(lsize - 1)); |
| 111 | const void *aend = (const void *)((stop - 1) & ~(lsize - 1)); |
Stefan Roese | 03d3bfb | 2009-01-21 17:20:20 +0100 | [diff] [blame] | 112 | |
| 113 | while (1) { |
Paul Burton | 2b8bcc5 | 2015-01-29 01:27:56 +0000 | [diff] [blame^] | 114 | mips_cache(HIT_WRITEBACK_INV_D, addr); |
Stefan Roese | 03d3bfb | 2009-01-21 17:20:20 +0100 | [diff] [blame] | 115 | if (addr == aend) |
| 116 | break; |
| 117 | addr += lsize; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | void invalidate_dcache_range(ulong start_addr, ulong stop) |
| 122 | { |
Paul Burton | fa476f7 | 2013-11-08 11:18:42 +0000 | [diff] [blame] | 123 | unsigned long lsize = dcache_line_size(); |
Paul Burton | 2b8bcc5 | 2015-01-29 01:27:56 +0000 | [diff] [blame^] | 124 | const void *addr = (const void *)(start_addr & ~(lsize - 1)); |
| 125 | const void *aend = (const void *)((stop - 1) & ~(lsize - 1)); |
Stefan Roese | 03d3bfb | 2009-01-21 17:20:20 +0100 | [diff] [blame] | 126 | |
| 127 | while (1) { |
Paul Burton | 2b8bcc5 | 2015-01-29 01:27:56 +0000 | [diff] [blame^] | 128 | mips_cache(HIT_INVALIDATE_D, addr); |
Stefan Roese | 03d3bfb | 2009-01-21 17:20:20 +0100 | [diff] [blame] | 129 | if (addr == aend) |
| 130 | break; |
| 131 | addr += lsize; |
| 132 | } |
| 133 | } |
| 134 | |
Shinya Kuribayashi | 03c031d | 2007-10-27 15:27:06 +0900 | [diff] [blame] | 135 | void write_one_tlb(int index, u32 pagemask, u32 hi, u32 low0, u32 low1) |
| 136 | { |
Shinya Kuribayashi | e2ad842 | 2008-05-30 00:53:38 +0900 | [diff] [blame] | 137 | write_c0_entrylo0(low0); |
| 138 | write_c0_pagemask(pagemask); |
| 139 | write_c0_entrylo1(low1); |
| 140 | write_c0_entryhi(hi); |
| 141 | write_c0_index(index); |
wdenk | 5da627a | 2003-10-09 20:09:04 +0000 | [diff] [blame] | 142 | tlb_write_indexed(); |
| 143 | } |
Shinya Kuribayashi | 5dfb3ee | 2008-10-19 12:08:50 +0900 | [diff] [blame] | 144 | |
| 145 | int cpu_eth_init(bd_t *bis) |
| 146 | { |
| 147 | #ifdef CONFIG_SOC_AU1X00 |
| 148 | au1x00_enet_initialize(bis); |
| 149 | #endif |
| 150 | return 0; |
| 151 | } |