rtt_api.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. * 2014-04-07 Grissiom first version
  9. */
  10. #ifndef __RTT_API_H__
  11. #define __RTT_API_H__
  12. /* 4MB in size */
  13. #define VMM_SIZE 0x400000
  14. #define VMM_END 0xc8000000
  15. #define VMM_BEGIN (VMM_END - VMM_SIZE)
  16. /* VMM Memory Map:
  17. *
  18. * --- VMM_BEGIN --- +------+
  19. * .vectors | 4KB |
  20. * .text.share | |
  21. * ----------------- + |
  22. * guest vector page | 4KB |
  23. * ----------------- + |
  24. * .data.share | 4KB |
  25. * ----------------- + |
  26. * .bss.share | 4KB |
  27. * -- SHARE_BASE -- + | 1MB
  28. * shared context | shared region
  29. * ----------------- |
  30. * blabla... |
  31. * ----------------- +------+
  32. * vmm text |
  33. * rodata |
  34. * blabla... |
  35. * ----------------- | private region
  36. * vmm data |
  37. * ----------------- |
  38. * vmm bss |
  39. * ---- VMM_END ---- +------+
  40. *
  41. */
  42. /* 1MB is one level one page table entry, if we want to page table to be
  43. * simple(avoid TLB miss), we could allocate 1MB for shared memory. */
  44. #define VMM_SHARE_PGSZ (1024*1024)
  45. /* the size and position of shared code text */
  46. #define VMM_SHARE_TEXT_PGSZ 4096
  47. /* the size and position of vector's page size in Linux */
  48. #define LINUX_VECTOR_PGSZ 4096
  49. #define LINUX_VECTOR_POS (VMM_BEGIN + VMM_SHARE_TEXT_PGSZ)
  50. /* the size and position of shared code data */
  51. #define VMM_SHARE_DATA_PGSZ 4096
  52. #define VMM_SHARE_DATA_POS (LINUX_VECTOR_POS + LINUX_VECTOR_PGSZ)
  53. /* the size and position of shared code bss */
  54. #define VMM_SHARE_BSS_PGSZ 4096
  55. #define VMM_SHARE_BSS_POS (VMM_SHARE_DATA_POS + VMM_SHARE_DATA_PGSZ)
  56. /* the size and position of shared code bss */
  57. #define VMM_SHARE_CTX_PGSZ (VMM_SHARE_PGSZ - \
  58. LINUX_VECTOR_PGSZ - \
  59. VMM_SHARE_TEXT_PGSZ - \
  60. VMM_SHARE_DATA_PGSZ - \
  61. VMM_SHARE_BSS_PGSZ)
  62. #if VMM_SHARE_CTX_PGSZ <= 0
  63. #error
  64. #endif
  65. #define VMM_SHARE_CTX_POS (VMM_SHARE_BSS_POS + VMM_SHARE_BSS_PGSZ)
  66. /* the size of FIQ stack page size in RT-Thread */
  67. #define RT_FIQ_STACK_PGSZ 0
  68. /* the size of IRQ stack page size in RT-Thread */
  69. #define RT_IRQ_STACK_PGSZ 4096
  70. #ifdef HEAP_END
  71. #undef HEAP_END
  72. #endif
  73. #define HEAP_END (VMM_END)
  74. #define RT_VMM_VIRQ_TRIGGER 10
  75. #define RT_VMM_STACK_SIZE 1024
  76. /* the max number of iomap entries */
  77. #define RT_VMM_IOMAP_MAXNR 16
  78. #ifndef __iomem
  79. #define __iomem
  80. #endif
  81. #define IRQS_NR_32 ((96 + 31)/32)
  82. /*#define RT_VMM_USING_DOMAIN*/
  83. #ifndef __ASSEMBLY__
  84. /* keep consistent with linux/arch/arm/include/vmm/vmm.h */
  85. struct vmm_context
  86. {
  87. /* the status of vGuest irq, read only for RT-Thread */
  88. volatile unsigned long virq_status;
  89. /* has interrupt pended on vGuest OS IRQ */
  90. volatile unsigned long virq_pended;
  91. /* pending interrupt for vGuest OS */
  92. volatile unsigned long virq_pending[IRQS_NR_32];
  93. };
  94. struct vmm_domain
  95. {
  96. /* the number of kernel domain */
  97. char kernel;
  98. /* the number of user domain */
  99. char user;
  100. /* the number of io domain */
  101. char io;
  102. /* the number of vmm domain */
  103. char vmm;
  104. /* the number of vmm_share domain */
  105. char vmm_share;
  106. };
  107. struct vmm_iomap
  108. {
  109. const char name[16]; /* iomap name */
  110. unsigned long pa; /* physical address */
  111. volatile void __iomem * va; /* virtual address */
  112. size_t size; /* memory size */
  113. };
  114. struct vmm_entry_param
  115. {
  116. struct vmm_iomap *iomap;
  117. struct vmm_domain *domain;
  118. };
  119. typedef void (*vmm_entry_t)(struct vmm_entry_param* param);
  120. struct rt_vmm_share_layout
  121. {
  122. struct vmm_context ctx;
  123. };
  124. #ifndef __KERNEL__
  125. /* not in Linux, use better type check */
  126. extern struct rt_vmm_share_layout rt_vmm_share;
  127. #define RT_VMM_SHARE (&rt_vmm_share)
  128. #else
  129. #define RT_VMM_SHARE ((struct rt_vmm_share_layout*)VMM_SHARE_CTX_POS)
  130. #endif
  131. #endif
  132. #endif /* end of include guard: __RTT_API_H__ */