rtt_api.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * serial.c UART driver
  3. *
  4. * COPYRIGHT (C) 2014, Shanghai Real-Thread Technology Co., Ltd
  5. *
  6. * This file is part of RT-Thread (http://www.rt-thread.org)
  7. *
  8. * All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. *
  24. * Change Logs:
  25. * Date Author Notes
  26. * 2014-04-07 Grissiom first version
  27. */
  28. #ifndef __RTT_API_H__
  29. #define __RTT_API_H__
  30. /* 4MB in size */
  31. #define VMM_SIZE 0x400000
  32. #define VMM_END 0xc8000000
  33. #define VMM_BEGIN (VMM_END - VMM_SIZE)
  34. /* VMM Memory Map:
  35. *
  36. * --- VMM_BEGIN --- +------+
  37. * .vectors | 4KB |
  38. * .text.share | |
  39. * ----------------- + |
  40. * guest vector page | 4KB |
  41. * ----------------- + |
  42. * .data.share | 4KB |
  43. * ----------------- + |
  44. * .bss.share | 4KB |
  45. * -- SHARE_BASE -- + | 1MB
  46. * shared context | shared region
  47. * ----------------- |
  48. * blabla... |
  49. * ----------------- +------+
  50. * vmm text |
  51. * rodata |
  52. * blabla... |
  53. * ----------------- | private region
  54. * vmm data |
  55. * ----------------- |
  56. * vmm bss |
  57. * ---- VMM_END ---- +------+
  58. *
  59. */
  60. /* 1MB is one level one page table entry, if we want to page table to be
  61. * simple(avoid TLB miss), we could allocate 1MB for shared memory. */
  62. #define VMM_SHARE_PGSZ (1024*1024)
  63. /* the size and position of shared code text */
  64. #define VMM_SHARE_TEXT_PGSZ 4096
  65. /* the size and position of vector's page size in Linux */
  66. #define LINUX_VECTOR_PGSZ 4096
  67. #define LINUX_VECTOR_POS (VMM_BEGIN + VMM_SHARE_TEXT_PGSZ)
  68. /* the size and position of shared code data */
  69. #define VMM_SHARE_DATA_PGSZ 4096
  70. #define VMM_SHARE_DATA_POS (LINUX_VECTOR_POS + LINUX_VECTOR_PGSZ)
  71. /* the size and position of shared code bss */
  72. #define VMM_SHARE_BSS_PGSZ 4096
  73. #define VMM_SHARE_BSS_POS (VMM_SHARE_DATA_POS + VMM_SHARE_DATA_PGSZ)
  74. /* the size and position of shared code bss */
  75. #define VMM_SHARE_CTX_PGSZ (VMM_SHARE_PGSZ - \
  76. LINUX_VECTOR_PGSZ - \
  77. VMM_SHARE_TEXT_PGSZ - \
  78. VMM_SHARE_DATA_PGSZ - \
  79. VMM_SHARE_BSS_PGSZ)
  80. #if VMM_SHARE_CTX_PGSZ <= 0
  81. #error
  82. #endif
  83. #define VMM_SHARE_CTX_POS (VMM_SHARE_BSS_POS + VMM_SHARE_BSS_PGSZ)
  84. /* the size of FIQ stack page size in RT-Thread */
  85. #define RT_FIQ_STACK_PGSZ 0
  86. /* the size of IRQ stack page size in RT-Thread */
  87. #define RT_IRQ_STACK_PGSZ 4096
  88. #ifdef HEAP_END
  89. #undef HEAP_END
  90. #endif
  91. #define HEAP_END (VMM_END)
  92. #define RT_VMM_VIRQ_TRIGGER 10
  93. #define RT_VMM_STACK_SIZE 1024
  94. /* the max number of iomap entries */
  95. #define RT_VMM_IOMAP_MAXNR 16
  96. #ifndef __iomem
  97. #define __iomem
  98. #endif
  99. #define IRQS_NR_32 ((96 + 31)/32)
  100. /*#define RT_VMM_USING_DOMAIN*/
  101. #ifndef __ASSEMBLY__
  102. /* keep consistent with linux/arch/arm/include/vmm/vmm.h */
  103. struct vmm_context
  104. {
  105. /* the status of vGuest irq, read only for RT-Thread */
  106. volatile unsigned long virq_status;
  107. /* has interrupt pended on vGuest OS IRQ */
  108. volatile unsigned long virq_pended;
  109. /* pending interrupt for vGuest OS */
  110. volatile unsigned long virq_pending[IRQS_NR_32];
  111. };
  112. struct vmm_domain
  113. {
  114. /* the number of kernel domain */
  115. char kernel;
  116. /* the number of user domain */
  117. char user;
  118. /* the number of io domain */
  119. char io;
  120. /* the number of vmm domain */
  121. char vmm;
  122. /* the number of vmm_share domain */
  123. char vmm_share;
  124. };
  125. struct vmm_iomap
  126. {
  127. const char name[16]; /* iomap name */
  128. unsigned long pa; /* physical address */
  129. volatile void __iomem * va; /* virtual address */
  130. size_t size; /* memory size */
  131. };
  132. struct vmm_entry_param
  133. {
  134. struct vmm_iomap *iomap;
  135. struct vmm_domain *domain;
  136. };
  137. typedef void (*vmm_entry_t)(struct vmm_entry_param* param);
  138. struct rt_vmm_share_layout
  139. {
  140. struct vmm_context ctx;
  141. };
  142. #ifndef __KERNEL__
  143. /* not in Linux, use better type check */
  144. extern struct rt_vmm_share_layout rt_vmm_share;
  145. #define RT_VMM_SHARE (&rt_vmm_share)
  146. #else
  147. #define RT_VMM_SHARE ((struct rt_vmm_share_layout*)VMM_SHARE_CTX_POS)
  148. #endif
  149. #endif
  150. #endif /* end of include guard: __RTT_API_H__ */