hpimsginit.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /******************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2014 AudioScience Inc. <support@audioscience.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License as
  6. published by the Free Software Foundation;
  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. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. Hardware Programming Interface (HPI) Utility functions.
  15. (C) Copyright AudioScience Inc. 2007
  16. *******************************************************************************/
  17. #include "hpi_internal.h"
  18. #include "hpimsginit.h"
  19. #include <linux/nospec.h>
  20. /* The actual message size for each object type */
  21. static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT;
  22. /* The actual response size for each object type */
  23. static u16 res_size[HPI_OBJ_MAXINDEX + 1] = HPI_RESPONSE_SIZE_BY_OBJECT;
  24. /* Flag to enable alternate message type for SSX2 bypass. */
  25. static u16 gwSSX2_bypass;
  26. /** \internal
  27. * initialize the HPI message structure
  28. */
  29. static void hpi_init_message(struct hpi_message *phm, u16 object,
  30. u16 function)
  31. {
  32. u16 size;
  33. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
  34. object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
  35. size = msg_size[object];
  36. } else {
  37. size = sizeof(*phm);
  38. }
  39. memset(phm, 0, size);
  40. phm->size = size;
  41. if (gwSSX2_bypass)
  42. phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
  43. else
  44. phm->type = HPI_TYPE_REQUEST;
  45. phm->object = object;
  46. phm->function = function;
  47. phm->version = 0;
  48. phm->adapter_index = HPI_ADAPTER_INDEX_INVALID;
  49. /* Expect actual adapter index to be set by caller */
  50. }
  51. /** \internal
  52. * initialize the HPI response structure
  53. */
  54. void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
  55. u16 error)
  56. {
  57. u16 size;
  58. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
  59. object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
  60. size = res_size[object];
  61. } else {
  62. size = sizeof(*phr);
  63. }
  64. memset(phr, 0, sizeof(*phr));
  65. phr->size = size;
  66. phr->type = HPI_TYPE_RESPONSE;
  67. phr->object = object;
  68. phr->function = function;
  69. phr->error = error;
  70. phr->specific_error = 0;
  71. phr->version = 0;
  72. }
  73. void hpi_init_message_response(struct hpi_message *phm,
  74. struct hpi_response *phr, u16 object, u16 function)
  75. {
  76. hpi_init_message(phm, object, function);
  77. /* default error return if the response is
  78. not filled in by the callee */
  79. hpi_init_response(phr, object, function,
  80. HPI_ERROR_PROCESSING_MESSAGE);
  81. }
  82. static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
  83. u16 object, u16 function)
  84. {
  85. memset(phm, 0, size);
  86. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
  87. phm->size = size;
  88. phm->type = HPI_TYPE_REQUEST;
  89. phm->object = object;
  90. phm->function = function;
  91. phm->version = 1;
  92. /* Expect adapter index to be set by caller */
  93. }
  94. }
  95. void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
  96. u16 object, u16 function)
  97. {
  98. (void)object;
  99. (void)function;
  100. memset(phr, 0, size);
  101. phr->size = size;
  102. phr->version = 1;
  103. phr->type = HPI_TYPE_RESPONSE;
  104. phr->error = HPI_ERROR_PROCESSING_MESSAGE;
  105. }
  106. void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,
  107. struct hpi_response_header *phr, u16 res_size, u16 object,
  108. u16 function)
  109. {
  110. hpi_init_messageV1(phm, msg_size, object, function);
  111. hpi_init_responseV1(phr, res_size, object, function);
  112. }