hpimsginit.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. /* The actual message size for each object type */
  20. static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT;
  21. /* The actual response size for each object type */
  22. static u16 res_size[HPI_OBJ_MAXINDEX + 1] = HPI_RESPONSE_SIZE_BY_OBJECT;
  23. /* Flag to enable alternate message type for SSX2 bypass. */
  24. static u16 gwSSX2_bypass;
  25. /** \internal
  26. * initialize the HPI message structure
  27. */
  28. static void hpi_init_message(struct hpi_message *phm, u16 object,
  29. u16 function)
  30. {
  31. u16 size;
  32. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
  33. size = msg_size[object];
  34. else
  35. size = sizeof(*phm);
  36. memset(phm, 0, size);
  37. phm->size = size;
  38. if (gwSSX2_bypass)
  39. phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
  40. else
  41. phm->type = HPI_TYPE_REQUEST;
  42. phm->object = object;
  43. phm->function = function;
  44. phm->version = 0;
  45. phm->adapter_index = HPI_ADAPTER_INDEX_INVALID;
  46. /* Expect actual adapter index to be set by caller */
  47. }
  48. /** \internal
  49. * initialize the HPI response structure
  50. */
  51. void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
  52. u16 error)
  53. {
  54. u16 size;
  55. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
  56. size = res_size[object];
  57. else
  58. size = sizeof(*phr);
  59. memset(phr, 0, sizeof(*phr));
  60. phr->size = size;
  61. phr->type = HPI_TYPE_RESPONSE;
  62. phr->object = object;
  63. phr->function = function;
  64. phr->error = error;
  65. phr->specific_error = 0;
  66. phr->version = 0;
  67. }
  68. void hpi_init_message_response(struct hpi_message *phm,
  69. struct hpi_response *phr, u16 object, u16 function)
  70. {
  71. hpi_init_message(phm, object, function);
  72. /* default error return if the response is
  73. not filled in by the callee */
  74. hpi_init_response(phr, object, function,
  75. HPI_ERROR_PROCESSING_MESSAGE);
  76. }
  77. static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
  78. u16 object, u16 function)
  79. {
  80. memset(phm, 0, size);
  81. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
  82. phm->size = size;
  83. phm->type = HPI_TYPE_REQUEST;
  84. phm->object = object;
  85. phm->function = function;
  86. phm->version = 1;
  87. /* Expect adapter index to be set by caller */
  88. }
  89. }
  90. void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
  91. u16 object, u16 function)
  92. {
  93. (void)object;
  94. (void)function;
  95. memset(phr, 0, size);
  96. phr->size = size;
  97. phr->version = 1;
  98. phr->type = HPI_TYPE_RESPONSE;
  99. phr->error = HPI_ERROR_PROCESSING_MESSAGE;
  100. }
  101. void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,
  102. struct hpi_response_header *phr, u16 res_size, u16 object,
  103. u16 function)
  104. {
  105. hpi_init_messageV1(phm, msg_size, object, function);
  106. hpi_init_responseV1(phr, res_size, object, function);
  107. }