mm_fault.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-12-06 WangXiaoyao the first version
  9. */
  10. #ifndef __MM_FAULT_H__
  11. #define __MM_FAULT_H__
  12. #include <rtthread.h>
  13. #include <stddef.h>
  14. #include <stdint.h>
  15. /* fast path fault handler, a page frame on kernel space is returned */
  16. #define MM_FAULT_STATUS_OK 0
  17. /* customized fault handler, done by using rt_varea_map_* */
  18. #define MM_FAULT_STATUS_OK_MAPPED 1
  19. #define MM_FAULT_STATUS_UNRECOVERABLE 4
  20. #define MM_FAULT_FIXABLE_FALSE 0
  21. #define MM_FAULT_FIXABLE_TRUE 1
  22. enum rt_mm_fault_op
  23. {
  24. MM_FAULT_OP_READ = 1,
  25. MM_FAULT_OP_WRITE,
  26. MM_FAULT_OP_EXECUTE,
  27. };
  28. enum rt_mm_fault_type
  29. {
  30. /**
  31. * Occurs when an instruction attempts to access a memory address that it
  32. * does not have permission to access
  33. */
  34. MM_FAULT_TYPE_ACCESS_FAULT,
  35. /**
  36. * Occurs when a load or store instruction accesses a virtual memory
  37. * address that is not currently mapped to a physical memory page
  38. */
  39. MM_FAULT_TYPE_PAGE_FAULT,
  40. /**
  41. * Occurs like a SIGBUS
  42. */
  43. MM_FAULT_TYPE_BUS_ERROR,
  44. MM_FAULT_TYPE_GENERIC,
  45. __PRIVATE_PAGE_INSERT,
  46. };
  47. enum rt_mm_hint_prefetch
  48. {
  49. MM_FAULT_HINT_PREFETCH_NONE,
  50. MM_FAULT_HINT_PREFETCH_READY,
  51. };
  52. struct rt_mm_fault_res
  53. {
  54. void *vaddr;
  55. rt_size_t size;
  56. int status;
  57. /* hint for prefetch strategy */
  58. enum rt_mm_hint_prefetch hint;
  59. };
  60. struct rt_aspace_fault_msg
  61. {
  62. enum rt_mm_fault_op fault_op;
  63. enum rt_mm_fault_type fault_type;
  64. rt_size_t off;
  65. void *fault_vaddr;
  66. struct rt_mm_fault_res response;
  67. };
  68. struct rt_aspace_io_msg
  69. {
  70. /* offset in varea */
  71. rt_size_t off;
  72. /* fault address in target address space */
  73. void *fault_vaddr;
  74. /* read/write buffer in kernel space */
  75. void *buffer_vaddr;
  76. struct rt_mm_fault_res response;
  77. };
  78. rt_inline void rt_mm_fault_res_init(struct rt_mm_fault_res *res)
  79. {
  80. res->vaddr = RT_NULL;
  81. res->size = 0;
  82. res->hint = MM_FAULT_HINT_PREFETCH_NONE;
  83. res->status = MM_FAULT_STATUS_UNRECOVERABLE;
  84. }
  85. rt_inline void rt_mm_io_msg_init(struct rt_aspace_io_msg *io, rt_size_t off, void *fault_vaddr, void *buffer_vaddr)
  86. {
  87. io->off = off;
  88. io->fault_vaddr = fault_vaddr;
  89. io->buffer_vaddr = buffer_vaddr;
  90. rt_mm_fault_res_init(&io->response);
  91. }
  92. struct rt_aspace;
  93. /* MMU base page fault handler, MM_FAULT_FIXABLE_TRUE/MM_FAULT_FIXABLE_FALSE will be returned */
  94. int rt_aspace_fault_try_fix(struct rt_aspace *aspace, struct rt_aspace_fault_msg *msg);
  95. #endif /* __MM_FAULT_H__ */