ipa_nat_utils.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. #ifndef IPA_NAT_UTILS_H
  30. #define IPA_NAT_UTILS_H
  31. #include <stdio.h>
  32. #include <string.h>
  33. #include <syslog.h>
  34. #include <time.h>
  35. #include <linux/msm_ipa.h>
  36. #ifndef FALSE
  37. #define FALSE 0
  38. #endif
  39. #ifndef TRUE
  40. #define TRUE 1
  41. #endif
  42. #define MAX_DMA_ENTRIES_FOR_ADD 4
  43. #define MAX_DMA_ENTRIES_FOR_DEL 3
  44. #if !defined(MSM_IPA_TESTS) && !defined(FEATURE_IPA_ANDROID)
  45. #ifdef USE_GLIB
  46. #include <glib.h>
  47. #define strlcpy g_strlcpy
  48. #else
  49. size_t strlcpy(char* dst, const char* src, size_t size);
  50. #endif
  51. #endif
  52. #define IPAERR(fmt, ...) printf("ERR: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
  53. #define IPAINFO(fmt, ...) printf("INFO: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
  54. #define IPAWARN(fmt, ...) printf("WARN: %s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
  55. #ifdef NAT_DEBUG
  56. #define IPADBG(fmt, ...) printf("%s:%d %s() " fmt, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);
  57. #else
  58. #define IPADBG(fmt, ...)
  59. #endif
  60. typedef struct
  61. {
  62. int fd;
  63. enum ipa_hw_type ver;
  64. } ipa_descriptor;
  65. ipa_descriptor* ipa_descriptor_open(void);
  66. void ipa_descriptor_close(
  67. ipa_descriptor*);
  68. void ipa_read_debug_info(
  69. const char* debug_file_path);
  70. static inline char* prep_ioc_nat_dma_cmd_4print(
  71. struct ipa_ioc_nat_dma_cmd* cmd_ptr,
  72. char* buf_ptr,
  73. uint32_t buf_sz )
  74. {
  75. uint32_t i, len, buf_left;
  76. if ( cmd_ptr && buf_ptr && buf_sz )
  77. {
  78. snprintf(
  79. buf_ptr,
  80. buf_sz,
  81. "NAT_DMA_CMD: mem_type(%u) entries(%u) ",
  82. cmd_ptr->mem_type,
  83. cmd_ptr->entries);
  84. for ( i = 0; i < cmd_ptr->entries; i++ )
  85. {
  86. len = strlen(buf_ptr);
  87. buf_left = buf_sz - len;
  88. if ( buf_left > 0 && buf_left < buf_sz )
  89. {
  90. snprintf(
  91. buf_ptr + len,
  92. buf_left,
  93. "[%u](table_index(0x%02X) base_addr(0x%02X) offset(0x%08X) data(0x%04X)) ",
  94. i,
  95. cmd_ptr->dma[i].table_index,
  96. cmd_ptr->dma[i].base_addr,
  97. cmd_ptr->dma[i].offset,
  98. (uint32_t) cmd_ptr->dma[i].data);
  99. }
  100. }
  101. }
  102. return buf_ptr;
  103. }
  104. #undef NANOS_PER_SEC
  105. #undef MICROS_PER_SEC
  106. #undef MILLIS_PER_SEC
  107. #define NANOS_PER_SEC 1000000000
  108. #define MICROS_PER_SEC 1000000
  109. #define MILLIS_PER_SEC 1000
  110. /**
  111. * A macro for converting seconds to nanoseconds...
  112. */
  113. #define SECS2NanSECS(x) ((x) * NANOS_PER_SEC)
  114. /**
  115. * A macro for converting seconds to microseconds...
  116. */
  117. #define SECS2MicSECS(x) ((x) * MICROS_PER_SEC)
  118. /**
  119. * A macro for converting seconds to milliseconds...
  120. */
  121. #define SECS2MilSECS(x) ((x) * MILLIS_PER_SEC)
  122. /******************************************************************************/
  123. typedef enum
  124. {
  125. TimeAsNanSecs = 0,
  126. TimeAsMicSecs = 1,
  127. TimeAsMilSecs = 2
  128. } TimeAs_t;
  129. #undef VALID_TIMEAS
  130. #define VALID_TIMEAS(ta) \
  131. ( (ta) == TimeAsNanSecs || \
  132. (ta) == TimeAsMicSecs || \
  133. (ta) == TimeAsMilSecs )
  134. int currTimeAs(
  135. TimeAs_t timeAs,
  136. uint64_t* valPtr );
  137. #endif /* IPA_NAT_UTILS_H */