ipa_nat_utils.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Copyright (c) 2013, 2018-2020 The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * Changes from Qualcomm Innovation Center are provided under the following license:
  30. *
  31. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  32. *
  33. * Redistribution and use in source and binary forms, with or without
  34. * modification, are permitted (subject to the limitations in the
  35. * disclaimer below) provided that the following conditions are met:
  36. *
  37. * * Redistributions of source code must retain the above copyright
  38. * notice, this list of conditions and the following disclaimer.
  39. *
  40. * * Redistributions in binary form must reproduce the above
  41. * copyright notice, this list of conditions and the following
  42. * disclaimer in the documentation and/or other materials provided
  43. * with the distribution.
  44. *
  45. * * Neither the name of Qualcomm Innovation Center, Inc. nor the names of its
  46. * contributors may be used to endorse or promote products derived
  47. * from this software without specific prior written permission.
  48. *
  49. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  50. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
  51. * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  52. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  53. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  54. * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  55. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  56. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  57. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  58. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  59. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  60. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  61. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  62. */
  63. #ifndef IPA_NAT_UTILS_H
  64. #define IPA_NAT_UTILS_H
  65. #include <stdlib.h>
  66. #include <stdio.h>
  67. #include <string.h>
  68. #include <syslog.h>
  69. #include <time.h>
  70. #include <linux/msm_ipa.h>
  71. #ifndef FALSE
  72. #define FALSE 0
  73. #endif
  74. #ifndef TRUE
  75. #define TRUE 1
  76. #endif
  77. #define MAX_DMA_ENTRIES_FOR_ADD 4
  78. #define MAX_DMA_ENTRIES_FOR_DEL 3
  79. #if !defined(MSM_IPA_TESTS) && !defined(FEATURE_IPA_ANDROID)
  80. #ifdef USE_GLIB
  81. #include <glib.h>
  82. #define strlcpy g_strlcpy
  83. #else
  84. size_t strlcpy(char* dst, const char* src, size_t size);
  85. #endif
  86. #endif
  87. #define IPAERR(fmt, ...) printf("ERR: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
  88. #define IPAINFO(fmt, ...) printf("INFO: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
  89. #define IPAWARN(fmt, ...) printf("WARN: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
  90. #ifdef NAT_DEBUG
  91. #define IPADBG(fmt, ...) printf("%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
  92. #else
  93. #define IPADBG(fmt, ...)
  94. #endif
  95. typedef struct
  96. {
  97. int fd;
  98. enum ipa_hw_type ver;
  99. } ipa_descriptor;
  100. ipa_descriptor* ipa_descriptor_open(void);
  101. void ipa_descriptor_close(
  102. ipa_descriptor*);
  103. void ipa_read_debug_info(
  104. const char* debug_file_path);
  105. static inline char* prep_ioc_nat_dma_cmd_4print(
  106. struct ipa_ioc_nat_dma_cmd* cmd_ptr,
  107. char* buf_ptr,
  108. uint32_t buf_sz )
  109. {
  110. uint32_t i, len, buf_left;
  111. if ( cmd_ptr && buf_ptr && buf_sz )
  112. {
  113. snprintf(
  114. buf_ptr,
  115. buf_sz,
  116. "NAT_DMA_CMD: mem_type(%u) entries(%u) ",
  117. cmd_ptr->mem_type,
  118. cmd_ptr->entries);
  119. for ( i = 0; i < cmd_ptr->entries; i++ )
  120. {
  121. len = strlen(buf_ptr);
  122. buf_left = buf_sz - len;
  123. if ( buf_left > 0 && buf_left < buf_sz )
  124. {
  125. snprintf(
  126. buf_ptr + len,
  127. buf_left,
  128. "[%u](table_index(0x%02X) base_addr(0x%02X) offset(0x%08X) data(0x%04X)) ",
  129. i,
  130. cmd_ptr->dma[i].table_index,
  131. cmd_ptr->dma[i].base_addr,
  132. cmd_ptr->dma[i].offset,
  133. (uint32_t) cmd_ptr->dma[i].data);
  134. }
  135. }
  136. }
  137. return buf_ptr;
  138. }
  139. #undef NANOS_PER_SEC
  140. #undef MICROS_PER_SEC
  141. #undef MILLIS_PER_SEC
  142. #define NANOS_PER_SEC 1000000000
  143. #define MICROS_PER_SEC 1000000
  144. #define MILLIS_PER_SEC 1000
  145. /**
  146. * A macro for converting seconds to nanoseconds...
  147. */
  148. #define SECS2NanSECS(x) ((x) * NANOS_PER_SEC)
  149. /**
  150. * A macro for converting seconds to microseconds...
  151. */
  152. #define SECS2MicSECS(x) ((x) * MICROS_PER_SEC)
  153. /**
  154. * A macro for converting seconds to milliseconds...
  155. */
  156. #define SECS2MilSECS(x) ((x) * MILLIS_PER_SEC)
  157. /******************************************************************************/
  158. typedef enum
  159. {
  160. TimeAsNanSecs = 0,
  161. TimeAsMicSecs = 1,
  162. TimeAsMilSecs = 2
  163. } TimeAs_t;
  164. #undef VALID_TIMEAS
  165. #define VALID_TIMEAS(ta) \
  166. ( (ta) == TimeAsNanSecs || \
  167. (ta) == TimeAsMicSecs || \
  168. (ta) == TimeAsMilSecs )
  169. int currTimeAs(
  170. TimeAs_t timeAs,
  171. uint64_t* valPtr );
  172. #endif /* IPA_NAT_UTILS_H */