fman_sp.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright 2008 - 2015 Freescale Semiconductor Inc.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * * Neither the name of Freescale Semiconductor nor the
  12. * names of its contributors may be used to endorse or promote products
  13. * derived from this software without specific prior written permission.
  14. *
  15. *
  16. * ALTERNATIVELY, this software may be distributed under the terms of the
  17. * GNU General Public License ("GPL") as published by the Free Software
  18. * Foundation, either version 2 of that License or (at your option) any
  19. * later version.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  22. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  25. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  26. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  28. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include "fman_sp.h"
  33. #include "fman.h"
  34. void fman_sp_set_buf_pools_in_asc_order_of_buf_sizes(struct fman_ext_pools
  35. *fm_ext_pools,
  36. u8 *ordered_array,
  37. u16 *sizes_array)
  38. {
  39. u16 buf_size = 0;
  40. int i = 0, j = 0, k = 0;
  41. /* First we copy the external buffers pools information
  42. * to an ordered local array
  43. */
  44. for (i = 0; i < fm_ext_pools->num_of_pools_used; i++) {
  45. /* get pool size */
  46. buf_size = fm_ext_pools->ext_buf_pool[i].size;
  47. /* keep sizes in an array according to poolId
  48. * for direct access
  49. */
  50. sizes_array[fm_ext_pools->ext_buf_pool[i].id] = buf_size;
  51. /* save poolId in an ordered array according to size */
  52. for (j = 0; j <= i; j++) {
  53. /* this is the next free place in the array */
  54. if (j == i)
  55. ordered_array[i] =
  56. fm_ext_pools->ext_buf_pool[i].id;
  57. else {
  58. /* find the right place for this poolId */
  59. if (buf_size < sizes_array[ordered_array[j]]) {
  60. /* move the pool_ids one place ahead
  61. * to make room for this poolId
  62. */
  63. for (k = i; k > j; k--)
  64. ordered_array[k] =
  65. ordered_array[k - 1];
  66. /* now k==j, this is the place for
  67. * the new size
  68. */
  69. ordered_array[k] =
  70. fm_ext_pools->ext_buf_pool[i].id;
  71. break;
  72. }
  73. }
  74. }
  75. }
  76. }
  77. EXPORT_SYMBOL(fman_sp_set_buf_pools_in_asc_order_of_buf_sizes);
  78. int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy *
  79. int_context_data_copy,
  80. struct fman_buffer_prefix_content *
  81. buffer_prefix_content,
  82. struct fman_sp_buf_margins *buf_margins,
  83. struct fman_sp_buffer_offsets *buffer_offsets,
  84. u8 *internal_buf_offset)
  85. {
  86. u32 tmp;
  87. /* Align start of internal context data to 16 byte */
  88. int_context_data_copy->ext_buf_offset = (u16)
  89. ((buffer_prefix_content->priv_data_size & (OFFSET_UNITS - 1)) ?
  90. ((buffer_prefix_content->priv_data_size + OFFSET_UNITS) &
  91. ~(u16)(OFFSET_UNITS - 1)) :
  92. buffer_prefix_content->priv_data_size);
  93. /* Translate margin and int_context params to FM parameters */
  94. /* Initialize with illegal value. Later we'll set legal values. */
  95. buffer_offsets->prs_result_offset = (u32)ILLEGAL_BASE;
  96. buffer_offsets->time_stamp_offset = (u32)ILLEGAL_BASE;
  97. buffer_offsets->hash_result_offset = (u32)ILLEGAL_BASE;
  98. /* Internally the driver supports 4 options
  99. * 1. prsResult/timestamp/hashResult selection (in fact 8 options,
  100. * but for simplicity we'll
  101. * relate to it as 1).
  102. * 2. All IC context (from AD) not including debug.
  103. */
  104. /* This case covers the options under 1 */
  105. /* Copy size must be in 16-byte granularity. */
  106. int_context_data_copy->size =
  107. (u16)((buffer_prefix_content->pass_prs_result ? 32 : 0) +
  108. ((buffer_prefix_content->pass_time_stamp ||
  109. buffer_prefix_content->pass_hash_result) ? 16 : 0));
  110. /* Align start of internal context data to 16 byte */
  111. int_context_data_copy->int_context_offset =
  112. (u8)(buffer_prefix_content->pass_prs_result ? 32 :
  113. ((buffer_prefix_content->pass_time_stamp ||
  114. buffer_prefix_content->pass_hash_result) ? 64 : 0));
  115. if (buffer_prefix_content->pass_prs_result)
  116. buffer_offsets->prs_result_offset =
  117. int_context_data_copy->ext_buf_offset;
  118. if (buffer_prefix_content->pass_time_stamp)
  119. buffer_offsets->time_stamp_offset =
  120. buffer_prefix_content->pass_prs_result ?
  121. (int_context_data_copy->ext_buf_offset +
  122. sizeof(struct fman_prs_result)) :
  123. int_context_data_copy->ext_buf_offset;
  124. if (buffer_prefix_content->pass_hash_result)
  125. /* If PR is not requested, whether TS is
  126. * requested or not, IC will be copied from TS
  127. */
  128. buffer_offsets->hash_result_offset =
  129. buffer_prefix_content->pass_prs_result ?
  130. (int_context_data_copy->ext_buf_offset +
  131. sizeof(struct fman_prs_result) + 8) :
  132. int_context_data_copy->ext_buf_offset + 8;
  133. if (int_context_data_copy->size)
  134. buf_margins->start_margins =
  135. (u16)(int_context_data_copy->ext_buf_offset +
  136. int_context_data_copy->size);
  137. else
  138. /* No Internal Context passing, STartMargin is
  139. * immediately after private_info
  140. */
  141. buf_margins->start_margins =
  142. buffer_prefix_content->priv_data_size;
  143. /* align data start */
  144. tmp = (u32)(buf_margins->start_margins %
  145. buffer_prefix_content->data_align);
  146. if (tmp)
  147. buf_margins->start_margins +=
  148. (buffer_prefix_content->data_align - tmp);
  149. buffer_offsets->data_offset = buf_margins->start_margins;
  150. return 0;
  151. }
  152. EXPORT_SYMBOL(fman_sp_build_buffer_struct);