cache.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * linux/arch/m32r/mm/cache.c
  3. *
  4. * Copyright (C) 2002-2005 Hirokazu Takata, Hayato Fujiwara
  5. */
  6. #include <asm/pgtable.h>
  7. #undef MCCR
  8. #if defined(CONFIG_CHIP_XNUX2) || defined(CONFIG_CHIP_M32700) \
  9. || defined(CONFIG_CHIP_VDEC2) || defined(CONFIG_CHIP_OPSP)
  10. /* Cache Control Register */
  11. #define MCCR ((volatile unsigned long*)0xfffffffc)
  12. #define MCCR_CC (1UL << 7) /* Cache mode modify bit */
  13. #define MCCR_IIV (1UL << 6) /* I-cache invalidate */
  14. #define MCCR_DIV (1UL << 5) /* D-cache invalidate */
  15. #define MCCR_DCB (1UL << 4) /* D-cache copy back */
  16. #define MCCR_ICM (1UL << 1) /* I-cache mode [0:off,1:on] */
  17. #define MCCR_DCM (1UL << 0) /* D-cache mode [0:off,1:on] */
  18. #define MCCR_ICACHE_INV (MCCR_CC|MCCR_IIV)
  19. #define MCCR_DCACHE_CB (MCCR_CC|MCCR_DCB)
  20. #define MCCR_DCACHE_CBINV (MCCR_CC|MCCR_DIV|MCCR_DCB)
  21. #define CHECK_MCCR(mccr) (mccr = *MCCR)
  22. #elif defined(CONFIG_CHIP_M32102)
  23. #define MCCR ((volatile unsigned char*)0xfffffffe)
  24. #define MCCR_IIV (1UL << 0) /* I-cache invalidate */
  25. #define MCCR_ICACHE_INV MCCR_IIV
  26. #elif defined(CONFIG_CHIP_M32104)
  27. #define MCCR ((volatile unsigned short*)0xfffffffe)
  28. #define MCCR_IIV (1UL << 8) /* I-cache invalidate */
  29. #define MCCR_DIV (1UL << 9) /* D-cache invalidate */
  30. #define MCCR_DCB (1UL << 10) /* D-cache copy back */
  31. #define MCCR_ICM (1UL << 0) /* I-cache mode [0:off,1:on] */
  32. #define MCCR_DCM (1UL << 1) /* D-cache mode [0:off,1:on] */
  33. #define MCCR_ICACHE_INV MCCR_IIV
  34. #define MCCR_DCACHE_CB MCCR_DCB
  35. #define MCCR_DCACHE_CBINV (MCCR_DIV|MCCR_DCB)
  36. #endif
  37. #ifndef MCCR
  38. #error Unknown cache type.
  39. #endif
  40. /* Copy back and invalidate D-cache and invalidate I-cache all */
  41. void _flush_cache_all(void)
  42. {
  43. #if defined(CONFIG_CHIP_M32102)
  44. unsigned char mccr;
  45. *MCCR = MCCR_ICACHE_INV;
  46. #elif defined(CONFIG_CHIP_M32104)
  47. unsigned short mccr;
  48. /* Copyback and invalidate D-cache */
  49. /* Invalidate I-cache */
  50. *MCCR |= (MCCR_ICACHE_INV | MCCR_DCACHE_CBINV);
  51. #else
  52. unsigned long mccr;
  53. /* Copyback and invalidate D-cache */
  54. /* Invalidate I-cache */
  55. *MCCR = MCCR_ICACHE_INV | MCCR_DCACHE_CBINV;
  56. #endif
  57. while ((mccr = *MCCR) & MCCR_IIV); /* loop while invalidating... */
  58. }
  59. /* Copy back D-cache and invalidate I-cache all */
  60. void _flush_cache_copyback_all(void)
  61. {
  62. #if defined(CONFIG_CHIP_M32102)
  63. unsigned char mccr;
  64. *MCCR = MCCR_ICACHE_INV;
  65. #elif defined(CONFIG_CHIP_M32104)
  66. unsigned short mccr;
  67. /* Copyback and invalidate D-cache */
  68. /* Invalidate I-cache */
  69. *MCCR |= (MCCR_ICACHE_INV | MCCR_DCACHE_CB);
  70. #else
  71. unsigned long mccr;
  72. /* Copyback D-cache */
  73. /* Invalidate I-cache */
  74. *MCCR = MCCR_ICACHE_INV | MCCR_DCACHE_CB;
  75. #endif
  76. while ((mccr = *MCCR) & MCCR_IIV); /* loop while invalidating... */
  77. }