q6common.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <dsp/q6common.h>
  13. struct q6common_ctl {
  14. bool instance_id_supported;
  15. };
  16. static struct q6common_ctl common;
  17. /**
  18. * q6common_update_instance_id_support
  19. *
  20. * Update instance ID support flag to true/false
  21. *
  22. * @supported: enable/disable for instance ID support
  23. */
  24. void q6common_update_instance_id_support(bool supported)
  25. {
  26. common.instance_id_supported = supported;
  27. }
  28. EXPORT_SYMBOL(q6common_update_instance_id_support);
  29. /**
  30. * q6common_is_instance_id_supported
  31. *
  32. * Returns true/false for instance ID support
  33. */
  34. bool q6common_is_instance_id_supported(void)
  35. {
  36. return common.instance_id_supported;
  37. }
  38. EXPORT_SYMBOL(q6common_is_instance_id_supported);
  39. /**
  40. * q6common_pack_pp_params
  41. *
  42. * Populate params header based on instance ID support and pack
  43. * it with payload.
  44. * Instance ID support -
  45. * yes - param_hdr_v3 + payload
  46. * no - param_hdr_v1 + payload
  47. *
  48. * @dest: destination data pointer to be packed into
  49. * @v3_hdr: param header v3
  50. * @param_data: param payload
  51. * @total_size: total size of packed data (hdr + payload)
  52. *
  53. * Returns 0 on success or error on failure
  54. */
  55. int q6common_pack_pp_params(u8 *dest, struct param_hdr_v3 *v3_hdr,
  56. u8 *param_data, u32 *total_size)
  57. {
  58. struct param_hdr_v1 *v1_hdr = NULL;
  59. u32 packed_size = 0;
  60. u32 param_size = 0;
  61. bool iid_supported = q6common_is_instance_id_supported();
  62. if (dest == NULL) {
  63. pr_err("%s: Received NULL pointer for destination\n", __func__);
  64. return -EINVAL;
  65. } else if (v3_hdr == NULL) {
  66. pr_err("%s: Received NULL pointer for header\n", __func__);
  67. return -EINVAL;
  68. } else if (total_size == NULL) {
  69. pr_err("%s: Received NULL pointer for total size\n", __func__);
  70. return -EINVAL;
  71. }
  72. param_size = v3_hdr->param_size;
  73. packed_size = iid_supported ? sizeof(struct param_hdr_v3) :
  74. sizeof(struct param_hdr_v1);
  75. if (iid_supported) {
  76. memcpy(dest, v3_hdr, packed_size);
  77. } else {
  78. v1_hdr = (struct param_hdr_v1 *) dest;
  79. v1_hdr->module_id = v3_hdr->module_id;
  80. v1_hdr->param_id = v3_hdr->param_id;
  81. if (param_size > U16_MAX) {
  82. pr_err("%s: Invalid param size for V1 %d\n", __func__,
  83. param_size);
  84. return -EINVAL;
  85. }
  86. v1_hdr->param_size = param_size;
  87. v1_hdr->reserved = 0;
  88. }
  89. /*
  90. * Make param_data optional for cases when there is no data
  91. * present as in some set cases and all get cases.
  92. */
  93. if (param_data != NULL) {
  94. memcpy(dest + packed_size, param_data, param_size);
  95. packed_size += param_size;
  96. }
  97. *total_size = packed_size;
  98. return 0;
  99. }
  100. EXPORT_SYMBOL(q6common_pack_pp_params);