hantrommu.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /****************************************************************************
  2. *
  3. * The MIT License (MIT)
  4. *
  5. * Copyright (c) 2014 - 2021 VERISILICON
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. *
  25. *****************************************************************************
  26. *
  27. * The GPL License (GPL)
  28. *
  29. * Copyright (C) 2014 - 2021 VERISILICON
  30. *
  31. * This program is free software; you can redistribute it and/or
  32. * modify it under the terms of the GNU General Public License
  33. * as published by the Free Software Foundation; either version 2
  34. * of the License, or (at your option) any later version.
  35. *
  36. * This program is distributed in the hope that it will be useful,
  37. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  38. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  39. * GNU General Public License for more details.
  40. *
  41. * You should have received a copy of the GNU General Public License
  42. * along with this program; if not, write to the Free Software Foundation,
  43. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  44. *
  45. *****************************************************************************
  46. *
  47. * Note: This software is released under dual MIT and GPL licenses. A
  48. * recipient may use this file under the terms of either the MIT license or
  49. * GPL License. If you wish to use only one license not the other, you can
  50. * indicate your decision by deleting one of the above license notices in your
  51. * version of this file.
  52. *
  53. *****************************************************************************/
  54. #ifndef _HANTROMMU_H_
  55. #define _HANTROMMU_H_
  56. #ifdef __cplusplus
  57. extern "C" {
  58. #endif
  59. #ifdef __FREERTOS__
  60. #elif defined(__linux__)
  61. #include <linux/fs.h>
  62. #endif
  63. #define REGION_IN_START 0x0
  64. #define REGION_IN_END 0x0
  65. #define REGION_OUT_START 0x0
  66. #define REGION_OUT_END 0x0
  67. #define REGION_PRIVATE_START 0x0
  68. #define REGION_PRIVATE_END 0x0
  69. #define REGION_IN_MMU_START 0x1000
  70. #define REGION_IN_MMU_END 0x40002000
  71. #define REGION_OUT_MMU_START 0x40002000
  72. #define REGION_OUT_MMU_END 0x40002000
  73. #define REGION_PRIVATE_MMU_START 0x40002000
  74. #define REGION_PRIVATE_MMU_END 0x40002000
  75. #define MMU_REG_OFFSET 0
  76. #define MMU_REG_HW_ID (MMU_REG_OFFSET + 6*4)
  77. #define MMU_REG_FLUSH (MMU_REG_OFFSET + 97*4)
  78. #define MMU_REG_PAGE_TABLE_ID (MMU_REG_OFFSET + 107*4)
  79. #define MMU_REG_CONTROL (MMU_REG_OFFSET + 226*4)
  80. #define MMU_REG_ADDRESS (MMU_REG_OFFSET + 227*4)
  81. #define MMU_REG_ADDRESS_MSB (MMU_REG_OFFSET + 228*4)
  82. #define MTLB_PCIE_START_ADDRESS 0x00100000
  83. #define PAGE_PCIE_START_ADDRESS 0x00200000 /* page_table_entry start address */
  84. #define STLB_PCIE_START_ADDRESS 0x00300000
  85. #define PAGE_TABLE_ENTRY_SIZE 64
  86. enum MMUStatus {
  87. MMU_STATUS_OK = 0,
  88. MMU_STATUS_FALSE = -1,
  89. MMU_STATUS_INVALID_ARGUMENT = -2,
  90. MMU_STATUS_INVALID_OBJECT = -3,
  91. MMU_STATUS_OUT_OF_MEMORY = -4,
  92. MMU_STATUS_NOT_FOUND = -19,
  93. };
  94. struct addr_desc {
  95. void *virtual_address; /* buffer virtual address */
  96. unsigned int bus_address; /* buffer physical address */
  97. unsigned int size; /* physical size */
  98. };
  99. struct kernel_addr_desc {
  100. unsigned long long bus_address; /* buffer virtual address */
  101. unsigned int mmu_bus_address; /* buffer physical address in MMU*/
  102. unsigned int size; /* physical size */
  103. };
  104. #define HANTRO_IOC_MMU 'm'
  105. #define HANTRO_IOCS_MMU_MEM_MAP _IOWR(HANTRO_IOC_MMU, 1, struct addr_desc *)
  106. #define HANTRO_IOCS_MMU_MEM_UNMAP _IOWR(HANTRO_IOC_MMU, 2, struct addr_desc *)
  107. #define HANTRO_IOCS_MMU_ENABLE _IOWR(HANTRO_IOC_MMU, 3, unsigned int *)
  108. #define HANTRO_IOCS_MMU_FLUSH _IOWR(HANTRO_IOC_MMU, 4, unsigned int *)
  109. #define HANTRO_IOC_MMU_MAXNR 4
  110. #define MAX_SUBSYS_NUM 4 /* up to 4 subsystem (temporary) */
  111. #define HXDEC_MAX_CORES MAX_SUBSYS_NUM /* used in hantro_dec.c */
  112. /* Init MMU, should be called in driver init function. */
  113. enum MMUStatus MMUInit(volatile unsigned char *hwregs);
  114. /* Clean up all data in MMU, should be called in driver cleanup function
  115. when rmmod driver*/
  116. enum MMUStatus MMUCleanup(volatile unsigned char *hwregs[MAX_SUBSYS_NUM][2]);
  117. /* The function should be called in driver realease function
  118. when driver exit unnormally */
  119. enum MMUStatus MMURelease(void *filp, volatile unsigned char *hwregs);
  120. enum MMUStatus MMUEnable(volatile unsigned char *hwregs[MAX_SUBSYS_NUM][2]);
  121. /* Used in kernel to map buffer */
  122. enum MMUStatus MMUKernelMemNodeMap(struct kernel_addr_desc *addr);
  123. /* Used in kernel to unmap buffer */
  124. enum MMUStatus MMUKernelMemNodeUnmap(struct kernel_addr_desc *addr);
  125. unsigned long long GetMMUAddress(void);
  126. long MMUIoctl(unsigned int cmd, void *filp, unsigned long arg,
  127. volatile unsigned char *hwregs[MAX_SUBSYS_NUM][2]);
  128. void MMURestore(volatile unsigned char *hwregs[MAX_SUBSYS_NUM][2]);
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif