cache.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * U-boot - cache.c
  3. *
  4. * Copyright (c) 2005-2008 Analog Devices Inc.
  5. *
  6. * (C) Copyright 2000-2004
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * Licensed under the GPL-2 or later.
  10. */
  11. #include <common.h>
  12. #include <asm/blackfin.h>
  13. #include <asm/mach-common/bits/mpu.h>
  14. void flush_cache(unsigned long addr, unsigned long size)
  15. {
  16. void *start_addr, *end_addr;
  17. int istatus, dstatus;
  18. /* no need to flush stuff in on chip memory (L1/L2/etc...) */
  19. if (addr >= 0xE0000000)
  20. return;
  21. start_addr = (void *)addr;
  22. end_addr = (void *)(addr + size);
  23. istatus = icache_status();
  24. dstatus = dcache_status();
  25. if (istatus) {
  26. if (dstatus)
  27. blackfin_icache_dcache_flush_range(start_addr, end_addr);
  28. else
  29. blackfin_icache_flush_range(start_addr, end_addr);
  30. } else if (dstatus)
  31. blackfin_dcache_flush_range(start_addr, end_addr);
  32. }
  33. void icache_enable(void)
  34. {
  35. bfin_write_IMEM_CONTROL(IMC | ENICPLB);
  36. SSYNC();
  37. }
  38. void icache_disable(void)
  39. {
  40. bfin_write_IMEM_CONTROL(0);
  41. SSYNC();
  42. }
  43. int icache_status(void)
  44. {
  45. return bfin_read_IMEM_CONTROL() & IMC;
  46. }
  47. void dcache_enable(void)
  48. {
  49. bfin_write_DMEM_CONTROL(ACACHE_BCACHE | ENDCPLB | PORT_PREF0);
  50. SSYNC();
  51. }
  52. void dcache_disable(void)
  53. {
  54. bfin_write_DMEM_CONTROL(0);
  55. SSYNC();
  56. }
  57. int dcache_status(void)
  58. {
  59. return bfin_read_DMEM_CONTROL() & ACACHE_BCACHE;
  60. }