fman_sp.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. int fman_sp_build_buffer_struct(struct fman_sp_int_context_data_copy *
  78. int_context_data_copy,
  79. struct fman_buffer_prefix_content *
  80. buffer_prefix_content,
  81. struct fman_sp_buf_margins *buf_margins,
  82. struct fman_sp_buffer_offsets *buffer_offsets,
  83. u8 *internal_buf_offset)
  84. {
  85. u32 tmp;
  86. /* Align start of internal context data to 16 byte */
  87. int_context_data_copy->ext_buf_offset = (u16)
  88. ((buffer_prefix_content->priv_data_size & (OFFSET_UNITS - 1)) ?
  89. ((buffer_prefix_content->priv_data_size + OFFSET_UNITS) &
  90. ~(u16)(OFFSET_UNITS - 1)) :
  91. buffer_prefix_content->priv_data_size);
  92. /* Translate margin and int_context params to FM parameters */
  93. /* Initialize with illegal value. Later we'll set legal values. */
  94. buffer_offsets->prs_result_offset = (u32)ILLEGAL_BASE;
  95. buffer_offsets->time_stamp_offset = (u32)ILLEGAL_BASE;
  96. buffer_offsets->hash_result_offset = (u32)ILLEGAL_BASE;
  97. /* Internally the driver supports 4 options
  98. * 1. prsResult/timestamp/hashResult selection (in fact 8 options,
  99. * but for simplicity we'll
  100. * relate to it as 1).
  101. * 2. All IC context (from AD) not including debug.
  102. */
  103. /* This case covers the options under 1 */
  104. /* Copy size must be in 16-byte granularity. */
  105. int_context_data_copy->size =
  106. (u16)((buffer_prefix_content->pass_prs_result ? 32 : 0) +
  107. ((buffer_prefix_content->pass_time_stamp ||
  108. buffer_prefix_content->pass_hash_result) ? 16 : 0));
  109. /* Align start of internal context data to 16 byte */
  110. int_context_data_copy->int_context_offset =
  111. (u8)(buffer_prefix_content->pass_prs_result ? 32 :
  112. ((buffer_prefix_content->pass_time_stamp ||
  113. buffer_prefix_content->pass_hash_result) ? 64 : 0));
  114. if (buffer_prefix_content->pass_prs_result)
  115. buffer_offsets->prs_result_offset =
  116. int_context_data_copy->ext_buf_offset;
  117. if (buffer_prefix_content->pass_time_stamp)
  118. buffer_offsets->time_stamp_offset =
  119. buffer_prefix_content->pass_prs_result ?
  120. (int_context_data_copy->ext_buf_offset +
  121. sizeof(struct fman_prs_result)) :
  122. int_context_data_copy->ext_buf_offset;
  123. if (buffer_prefix_content->pass_hash_result)
  124. /* If PR is not requested, whether TS is
  125. * requested or not, IC will be copied from TS
  126. */
  127. buffer_offsets->hash_result_offset =
  128. buffer_prefix_content->pass_prs_result ?
  129. (int_context_data_copy->ext_buf_offset +
  130. sizeof(struct fman_prs_result) + 8) :
  131. int_context_data_copy->ext_buf_offset + 8;
  132. if (int_context_data_copy->size)
  133. buf_margins->start_margins =
  134. (u16)(int_context_data_copy->ext_buf_offset +
  135. int_context_data_copy->size);
  136. else
  137. /* No Internal Context passing, STartMargin is
  138. * immediately after private_info
  139. */
  140. buf_margins->start_margins =
  141. buffer_prefix_content->priv_data_size;
  142. /* align data start */
  143. tmp = (u32)(buf_margins->start_margins %
  144. buffer_prefix_content->data_align);
  145. if (tmp)
  146. buf_margins->start_margins +=
  147. (buffer_prefix_content->data_align - tmp);
  148. buffer_offsets->data_offset = buf_margins->start_margins;
  149. return 0;
  150. }