hpimsginit.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /******************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2010 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. * Used by ASIO driver to disable SSX2 for a single process
  27. * \param phSubSys Pointer to HPI subsystem handle.
  28. * \param wBypass New bypass setting 0 = off, nonzero = on
  29. * \return Previous bypass setting.
  30. */
  31. u16 hpi_subsys_ssx2_bypass(const struct hpi_hsubsys *ph_subsys, u16 bypass)
  32. {
  33. u16 old_value = gwSSX2_bypass;
  34. gwSSX2_bypass = bypass;
  35. return old_value;
  36. }
  37. /** \internal
  38. * initialize the HPI message structure
  39. */
  40. static void hpi_init_message(struct hpi_message *phm, u16 object,
  41. u16 function)
  42. {
  43. memset(phm, 0, sizeof(*phm));
  44. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
  45. phm->size = msg_size[object];
  46. else
  47. phm->size = sizeof(*phm);
  48. if (gwSSX2_bypass)
  49. phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
  50. else
  51. phm->type = HPI_TYPE_MESSAGE;
  52. phm->object = object;
  53. phm->function = function;
  54. phm->version = 0;
  55. /* Expect adapter index to be set by caller */
  56. }
  57. /** \internal
  58. * initialize the HPI response structure
  59. */
  60. void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
  61. u16 error)
  62. {
  63. memset(phr, 0, sizeof(*phr));
  64. phr->type = HPI_TYPE_RESPONSE;
  65. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
  66. phr->size = res_size[object];
  67. else
  68. phr->size = sizeof(*phr);
  69. phr->object = object;
  70. phr->function = function;
  71. phr->error = error;
  72. phr->specific_error = 0;
  73. phr->version = 0;
  74. }
  75. void hpi_init_message_response(struct hpi_message *phm,
  76. struct hpi_response *phr, u16 object, u16 function)
  77. {
  78. hpi_init_message(phm, object, function);
  79. /* default error return if the response is
  80. not filled in by the callee */
  81. hpi_init_response(phr, object, function,
  82. HPI_ERROR_PROCESSING_MESSAGE);
  83. }
  84. static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
  85. u16 object, u16 function)
  86. {
  87. memset(phm, 0, sizeof(*phm));
  88. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
  89. phm->size = size;
  90. phm->type = HPI_TYPE_MESSAGE;
  91. phm->object = object;
  92. phm->function = function;
  93. phm->version = 1;
  94. /* Expect adapter index to be set by caller */
  95. }
  96. }
  97. void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
  98. u16 object, u16 function)
  99. {
  100. memset(phr, 0, sizeof(*phr));
  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. }