hpimsginit.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /******************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2011 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. memset(phm, 0, sizeof(*phm));
  32. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
  33. phm->size = msg_size[object];
  34. else
  35. phm->size = sizeof(*phm);
  36. if (gwSSX2_bypass)
  37. phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
  38. else
  39. phm->type = HPI_TYPE_REQUEST;
  40. phm->object = object;
  41. phm->function = function;
  42. phm->version = 0;
  43. phm->adapter_index = HPI_ADAPTER_INDEX_INVALID;
  44. /* Expect actual adapter index to be set by caller */
  45. }
  46. /** \internal
  47. * initialize the HPI response structure
  48. */
  49. void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
  50. u16 error)
  51. {
  52. memset(phr, 0, sizeof(*phr));
  53. phr->type = HPI_TYPE_RESPONSE;
  54. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
  55. phr->size = res_size[object];
  56. else
  57. phr->size = sizeof(*phr);
  58. phr->object = object;
  59. phr->function = function;
  60. phr->error = error;
  61. phr->specific_error = 0;
  62. phr->version = 0;
  63. }
  64. void hpi_init_message_response(struct hpi_message *phm,
  65. struct hpi_response *phr, u16 object, u16 function)
  66. {
  67. hpi_init_message(phm, object, function);
  68. /* default error return if the response is
  69. not filled in by the callee */
  70. hpi_init_response(phr, object, function,
  71. HPI_ERROR_PROCESSING_MESSAGE);
  72. }
  73. static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
  74. u16 object, u16 function)
  75. {
  76. memset(phm, 0, sizeof(*phm));
  77. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
  78. phm->size = size;
  79. phm->type = HPI_TYPE_REQUEST;
  80. phm->object = object;
  81. phm->function = function;
  82. phm->version = 1;
  83. /* Expect adapter index to be set by caller */
  84. }
  85. }
  86. void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
  87. u16 object, u16 function)
  88. {
  89. memset(phr, 0, sizeof(*phr));
  90. phr->size = size;
  91. phr->version = 1;
  92. phr->type = HPI_TYPE_RESPONSE;
  93. phr->error = HPI_ERROR_PROCESSING_MESSAGE;
  94. }
  95. void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,
  96. struct hpi_response_header *phr, u16 res_size, u16 object,
  97. u16 function)
  98. {
  99. hpi_init_messageV1(phm, msg_size, object, function);
  100. hpi_init_responseV1(phr, res_size, object, function);
  101. }