cpu.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <netdev.h>
  10. #include <asm/mipsregs.h>
  11. #include <asm/cacheops.h>
  12. #include <asm/reboot.h>
  13. #define cache_op(op, addr) \
  14. __asm__ __volatile__( \
  15. " .set push\n" \
  16. " .set noreorder\n" \
  17. " .set mips64\n" \
  18. " cache %0, %1\n" \
  19. " .set pop\n" \
  20. : \
  21. : "i" (op), "R" (*(unsigned char *)(addr)))
  22. void __attribute__((weak)) _machine_restart(void)
  23. {
  24. fprintf(stderr, "*** reset failed ***\n");
  25. while (1)
  26. /* NOP */;
  27. }
  28. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  29. {
  30. _machine_restart();
  31. return 0;
  32. }
  33. void flush_cache(ulong start_addr, ulong size)
  34. {
  35. unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
  36. unsigned long addr = start_addr & ~(lsize - 1);
  37. unsigned long aend = (start_addr + size - 1) & ~(lsize - 1);
  38. /* aend will be miscalculated when size is zero, so we return here */
  39. if (size == 0)
  40. return;
  41. while (1) {
  42. cache_op(HIT_WRITEBACK_INV_D, addr);
  43. cache_op(HIT_INVALIDATE_I, addr);
  44. if (addr == aend)
  45. break;
  46. addr += lsize;
  47. }
  48. }
  49. void flush_dcache_range(ulong start_addr, ulong stop)
  50. {
  51. unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
  52. unsigned long addr = start_addr & ~(lsize - 1);
  53. unsigned long aend = (stop - 1) & ~(lsize - 1);
  54. while (1) {
  55. cache_op(HIT_WRITEBACK_INV_D, addr);
  56. if (addr == aend)
  57. break;
  58. addr += lsize;
  59. }
  60. }
  61. void invalidate_dcache_range(ulong start_addr, ulong stop)
  62. {
  63. unsigned long lsize = CONFIG_SYS_CACHELINE_SIZE;
  64. unsigned long addr = start_addr & ~(lsize - 1);
  65. unsigned long aend = (stop - 1) & ~(lsize - 1);
  66. while (1) {
  67. cache_op(HIT_INVALIDATE_D, addr);
  68. if (addr == aend)
  69. break;
  70. addr += lsize;
  71. }
  72. }
  73. void write_one_tlb(int index, u32 pagemask, u32 hi, u32 low0, u32 low1)
  74. {
  75. write_c0_entrylo0(low0);
  76. write_c0_pagemask(pagemask);
  77. write_c0_entrylo1(low1);
  78. write_c0_entryhi(hi);
  79. write_c0_index(index);
  80. tlb_write_indexed();
  81. }