mmu.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-11-28 GuEe-GUI the first version
  9. */
  10. #ifndef __MMU_H_
  11. #define __MMU_H_
  12. #include <rtthread.h>
  13. /* normal memory wra mapping type */
  14. #define NORMAL_MEM 0
  15. /* normal nocache memory mapping type */
  16. #define NORMAL_NOCACHE_MEM 1
  17. /* device mapping type */
  18. #define DEVICE_MEM 2
  19. #define MMU_MAP_ERROR_VANOTALIGN (-1)
  20. #define MMU_MAP_ERROR_PANOTALIGN (-2)
  21. #define MMU_MAP_ERROR_NOPAGE (-3)
  22. #define MMU_MAP_ERROR_CONFLICT (-4)
  23. struct mem_desc
  24. {
  25. unsigned long vaddr_start;
  26. unsigned long vaddr_end;
  27. unsigned long paddr_start;
  28. unsigned long attr;
  29. };
  30. #define MMU_AF_SHIFT 10
  31. #define MMU_SHARED_SHIFT 8
  32. #define MMU_AP_SHIFT 6
  33. #define MMU_MA_SHIFT 2
  34. #define MMU_AP_KAUN 0UL /* kernel r/w, user none */
  35. #define MMU_AP_KAUA 1UL /* kernel r/w, user r/w */
  36. #define MMU_AP_KRUN 2UL /* kernel r, user none */
  37. #define MMU_AP_KRUR 3UL /* kernel r, user r */
  38. #define MMU_MAP_CUSTOM(ap, mtype) \
  39. (\
  40. (0x1UL << MMU_AF_SHIFT) |\
  41. (0x2UL << MMU_SHARED_SHIFT) |\
  42. ((ap) << MMU_AP_SHIFT) |\
  43. ((mtype) << MMU_MA_SHIFT)\
  44. )
  45. #define MMU_MAP_K_RO MMU_MAP_CUSTOM(MMU_AP_KRUN, NORMAL_MEM)
  46. #define MMU_MAP_K_RWCB MMU_MAP_CUSTOM(MMU_AP_KAUN, NORMAL_MEM)
  47. #define MMU_MAP_K_RW MMU_MAP_CUSTOM(MMU_AP_KAUN, NORMAL_NOCACHE_MEM)
  48. #define MMU_MAP_K_DEVICE MMU_MAP_CUSTOM(MMU_AP_KAUN, DEVICE_MEM)
  49. #define MMU_MAP_U_RO MMU_MAP_CUSTOM(MMU_AP_KRUR, NORMAL_NOCACHE_MEM)
  50. #define MMU_MAP_U_RWCB MMU_MAP_CUSTOM(MMU_AP_KAUA, NORMAL_MEM)
  51. #define MMU_MAP_U_RW MMU_MAP_CUSTOM(MMU_AP_KAUA, NORMAL_NOCACHE_MEM)
  52. #define MMU_MAP_U_DEVICE MMU_MAP_CUSTOM(MMU_AP_KAUA, DEVICE_MEM)
  53. void rt_hw_init_mmu_table(struct mem_desc *mdesc, rt_size_t desc_nr);
  54. void rt_hw_mmu_init(void);
  55. int rt_hw_mmu_map(unsigned long addr, unsigned long size, unsigned long attr);
  56. void rt_hw_dcache_flush_all(void);
  57. void rt_hw_dcache_invalidate_all(void);
  58. void rt_hw_dcache_flush_range(unsigned long start_addr, unsigned long size);
  59. void rt_hw_dcache_invalidate_range(unsigned long start_addr,unsigned long size);
  60. void rt_hw_icache_invalidate_all();
  61. void rt_hw_icache_invalidate_range(unsigned long start_addr, int size);
  62. #endif /* __MMU_H_ */